本文介绍了从Celery中的tasket_id中检索GroupResult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用celery组来启动一组celery任务,如

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

我还将组(任务集)ID存储到db中,以便针对任务集状态轮询celery。

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

有没有一种方法可以从任务集ID开始获取GroupResult对象(即我的结果)?
类似于,但与芹菜团体合作。

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.

我已经尝试过:

r = GroupResult(taskset_id)

但它不起作用,如 r.results()始终为空。

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

我应该使用 GroupResult.save() GroupResult.restore()

推荐答案

是的保存结果,然后将其恢复。

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.

这篇关于从Celery中的tasket_id中检索GroupResult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:34