GAE跨服务任务提交:Python3服务提交任务至NodeJS18服务执行
GAE任务队列跨服务执行问题解答
1. Python3服务提交任务指定由NodeJS18服务执行
支持该操作。使用google.cloud.tasks_v2客户端提交任务时,需在AppEngineHttpRequest配置中添加service参数,明确指定处理任务的NodeJS18服务名称。
示例Python代码片段:
from google.cloud import tasks_v2 client = tasks_v2.CloudTasksClient() parent = client.queue_path("你的项目ID", "你的区域", "default") task = { "app_engine_http_request": { "http_method": tasks_v2.HttpMethod.POST, "relative_uri": "/你的任务处理路径", "service": "你的NodeJS18服务名称" # 关键:指定目标服务 } } response = client.create_task(request={"parent": parent, "task": task})
2. NodeJS18服务提交任务到default队列的执行方
如果提交任务时未指定service参数,且队列未配置默认target,任务会由提交该任务的NodeJS18服务执行;若队列通过queue.yaml或queue.xml配置了默认target,则会优先使用队列指定的服务执行任务。
示例队列配置(queue.yaml):
queue: - name: default target: python3-service # 队列默认绑定的处理服务
这种情况下,无论哪个服务向default队列提交任务,都会由python3-service执行,除非任务自身指定了其他service。
内容的提问来源于stack exchange,提问作者minou
相关产品推荐
相关产品推荐

