gpt4 book ai didi

python - 重试 block 内 celery 任务的行为

转载 作者:太空宇宙 更新时间:2023-11-04 06:42:29 26 4
gpt4 key购买 nike

我有一个关于在 chunk 中重试 celery 任务的问题.我的python版本是2.7.9,我的celery版本是3.1.18

当一个 block 中的单个任务失败时,它似乎没有被重试,而是整个 block 一起失败。

首先,有时会失败的任务:

@app.task(bind=True, default_retry_delay=30, max_retries=5)
def sometimes_add(self, x, y):
try:
if random.randint(0, 10) < 8:
return x + y
else:
raise Exception("I'm failing!")
except Exception as e:
raise self.sometimes_add.retry(exc=e)

任务调用了 100 次,分成 5 block ,因此有 20 个任务:

sometimes_add.chunks(zip(range(100), range(100)), 5).apply_async()

我希望 block 中失败的任务一旦失败就会重试,但似乎根本没有任务被重试,而且 5 个任务的整个 block 作为一个单元失败。

我是 Celery 的新手,所以很可能是我遗漏了一些对于使用任务分块的最佳方式来说相当基础的东西。如果是这样,我将不胜感激任何反馈。非常感谢!

最佳答案

您是否设置了结果后端?来自docs :

Tasks used within a chord must not ignore their results. In practice this means that you must enable a CELERY_RESULT_BACKEND in order to use chords. Additionally, if CELERY_IGNORE_RESULT is set to True in your configuration, be sure that the individual tasks to be used within the chord are defined with ignore_result=False. This applies to both Task subclasses and decorated tasks.

关于python - 重试 block 内 celery 任务的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30653216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com