gpt4 book ai didi

redis - 使用 django-celery chord,celery.chord_unlock 一直在执行,不调用提供的回调

转载 作者:IT王子 更新时间:2023-10-29 05:55:47 28 4
gpt4 key购买 nike

我正在使用 Django Celery 和 Redis 来运行一些这样的任务:

header = [
tasks.invalidate_user.subtask(args = (user)),
tasks.invalidate_details.subtask(args = (user))
]

callback = tasks.rebuild.subtask()

chord(header)(callback)

所以与documentation中所述基本相同.

我的问题是,当调用此任务 chord 时,celery.chord_unlock 任务一直在重试header 中的任务成功完成,但由于 chord_unlock 从未完成,因此永远不会调用 callback

猜测我的问题是无法检测到 header 中的任务已完成,我转向文档以查看如何对其进行自定义。我找到了 a section ,描述了如何实现同步,提供了一个示例,我缺少的是如何调用该示例函数(即是否有信号?)。

此外,请注意此方法不与 Redis 后端一起使用:

This is used by all result backends except Redis and Memcached, which increment a counter after each task in the header, then applying the callback when the counter exceeds the number of tasks in the set.

但也说,Redis 方法更好:

The Redis and Memcached approach is a much better solution

那是什么方法?如何实现?

那么,为什么 chord_unlock 从未完成,我怎样才能让它检测到完成的 header 任务?

我正在使用:Django 1.4、celery 2.5.3、django-celery 2.5.5、redis 2.4.12

最佳答案

您没有您的任务示例,但我遇到了同样的问题,我的解决方案可能适用。

我在添加到和弦的任务上设置了ignore_result=True,定义如下:

@task(ignore_result=True)

显然忽略结果使得 chord_unlock 任务不知道它们已经完成。在我删除 ignore_result 之后(即使任务只返回 true),chord 正确地调用了回调。

关于redis - 使用 django-celery chord,celery.chord_unlock 一直在执行,不调用提供的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438557/

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