【问题标题】:Attempting to retrieve a Celery GroupResult using ID, with an AMQP backend尝试使用 ID 和 AMQP 后端检索 Celery GroupResult
【发布时间】:2016-02-23 16:21:46
【问题描述】:

在将 Celery 与 RabbitMQ 一起使用时,我遇到了一个非常棘手的问题。

我有类似的东西:

from celery import group
group_of_tasks = group(task.s(x) for x in job_list)
result = group_of_tasks.delay()
print result.id  # let's call this d453359d...

以上工作正常,没有问题,我可以在 result.results 中查询组的状态以及单个 AsyncResults。

但是,如果我尝试在单独的控制台中执行以下操作:

from celery.result import GroupResult
x = GroupResult.restore('d453359d...')

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\celery\result.py", line 806, in restore
     ).restore_group(id)
  File "C:\Python27\lib\site-packages\celery\backends\amqp.py", line 297, in restore_group
    'restore_group is not supported by this backend.')
NotImplementedError: restore_group is not supported by this backend.

我在Retrieving GroupResult from taskset_id in Celery? 中遇到了一个类似的问题,其中提到了.save,但使用它也会导致NotImplementedError 被抛出。

celery.backends.amqp 中定义的 AMQP 后端的来源如下:

def save_group(self, group_id, result):
    raise NotImplementedError(
        'save_group is not supported by this backend.')

def restore_group(self, group_id, cache=True):
    raise NotImplementedError(
        'restore_group is not supported by this backend.')

所以,我的问题是,我有没有办法仅使用GroupResult ID 重新创建一组结果?唯一的方法是将每个AsyncResults 的ID 存储在组中并查询每个?

或者我只是在这里遗漏了一些非常明显的东西?

我正在使用 RabbitMQ 在 Windows 上的 Python 2.7.10 上运行 Celery。

【问题讨论】:

    标签: python celery celery-task


    【解决方案1】:

    您是对的 - 在使用 RabbitMQ 时无法重新创建结果组 - 您将需要使用支持此操作的不同结果后端,例如 Redis。

    【讨论】:

    • 感谢您的回答!我觉得 AMQP 没有办法(我必须坚持下去,因为我们需要可靠性和持久性),但我想确保我没有遗漏任何东西。
    • 你知道redis提供persistencereplication,对吧?
    • 哇。这就是我喜欢SO的原因。感谢这些链接,@scytale,我会看看 Redis 是否对这个项目更有意义。
    • 我推荐rabbitmq作为代理,redis作为结果后端
    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    相关资源
    最近更新 更多