我的用例: (芹菜任务A在服务器A上运行,芹菜任务B在服务器B上运行)
taskA(在服务器A上)->调用并等待taskB(在服务器B上)->taskA(在服务器A上)->继续处理taskB的结果
伪代码:
在服务器A上
@task
def taskA():
remoteTask = current_app.send_task("taskB", exchange="xxx", routing_key="serverB")
result = t.get()
# process result
在服务器B上
@task
def taskB():
# do something
return result
该代码显然违反了芹菜官方指南中提到的"Avoid launching synchronous subtasks"规则。我可以从控制台看到死锁警告。你知道吗
因此,我尝试用签名方法和或运算符重写子任务样式的代码
@task
def taskA()
remoteTask = signature("taskB", exchange="xxx", routing_key="serverB")
followingTask = signature("taskAA", exchange="xxx", routing_key="serverA")
chain = remoteTask | followingTask
return chain()
@task
def taskAA(result)
# process result
死锁警告消失了,但代码似乎不那么清楚。你知道吗
有没有更好的解决办法?还是我错过了什么?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐