Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving GroupResult from taskset_id in Celery?

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?

like image 580
Andrea Avatar asked Dec 03 '12 14:12

Andrea


1 Answers

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.

like image 63
bearnard Avatar answered Oct 17 '22 05:10

bearnard