Retrieving GroupResult from taskset_id in Celery?

ぃ、小莉子 提交于 2019-12-18 15:47:50

问题


I am starting a set of celery tasks by using celery group as described in the official documentation

I am also storing the group (taskset) id into a db, in order to poll celery for the taskset state.

job = group([
        single_test.s(1, 1),
        single_test.s(1, 2),
        single_test.s(1, 3),
    ])

result = job.apply_async()

test_set = MyTestSet()
test_set.taskset_id = result.id

# store test_set into DB

Is there a way to obtain a GroupResult object (i.e. my result) starting from the taskset id? Something like what is done in this question, but working with celery groups.

I already tried doing:

r = GroupResult(taskset_id)

but it does not work, as r.results() is always empty.

Should I use GroupResult.save() and GroupResult.restore() methods?


回答1:


Yes you have to save the result and then restore it.

job = group([
    single_test.s(1, 1),
    single_test.s(1, 2),
    single_test.s(1, 3),
])
result = job.apply_async()
result.save()

from celery.result import GroupResult
saved_result = GroupResult.restore(result.id)

I had the same issue and after seeing your hint about save/restore eventually figured it out.



来源:https://stackoverflow.com/questions/13685344/retrieving-groupresult-from-taskset-id-in-celery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!