使用芹菜4.3.0链时, 像这样的代码:
class BaseTask(Task):
def on_success(self, retval, task_id, args, kwargs):
pass
@app.task(bind=True, base=BaseTask)
def add(self, x, y):
return x+y
@app.task(bind=True, base=baseTask)
def add_1(self,x, y):
return x+y
task = group(add.s(1,3), add_1.s(2,4))()
group_id = task.id
我可以通过taks.children [0] ._ cache.get(“ group”)获得group_id,
如何在BaseTask的on_success函数中获取group_id?
答案 0 :(得分:0)
您可以在app.task.Request
对象中找到任务组的ID,该对象组可以通过Task
对象使用,如下所示:
class BaseTask(Task):
def on_success(self, retval, task_id, args, kwargs):
group_id = self.request.group
# rest of your code