通过任务 ID 重试 celery 中的任务

发布于 2024-10-19 16:28:36 字数 96 浏览 8 评论 0原文

我启动了很多任务,但其中一些尚未完成(763 个任务),处于 PENDING 状态,但系统未处理任何内容... 是否可以通过给 celery 提供 task_id 来重试此任务?

I've launched a lot of tasks, but some of then hasn't finished (763 tasks), are in a PENDING state, but the system isn't processing anything...
It's possible to retry this tasks giving celery the task_id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

物价感观 2024-10-26 16:28:36

你不能。
您只能从内部重试任务,而不能从外部执行此操作。

在这种情况下,最好的办法是使用相同的参数再次运行任务类型,这样您将执行相同的作业,但使用标识您的进程/任务的新 PID。

还要记住,celery PENDING 状态不仅意味着任务正在等待执行,而且可能是未知的。

http://celeryq.org/docs/userguide/tasks.html#pending

我希望这能有所帮助

You can't.
You can retry a task only from inside itself, you can't do it from outside.

The best thing to do in this case is to run again the task type with the same args, in this way you will do the same JOB but with a new PID that identify your process/task.

Remember also that the celery PENDING state not means only that the task is waiting for execution, but maybe that is unknown.

http://celeryq.org/docs/userguide/tasks.html#pending

I hope this could help

行至春深 2024-10-26 16:28:36

现在,在设置 celery.conf.update(result_extended=True) 后,它可以保留传递给任务的参数:

def retry_task(task_id):    
    meta=celery.backend.get_task_meta(task_id)
    task = celery.tasks[meta['name']]
    task.apply_async(args=meta['args'], kwargs=meta['kwargs']) #specify any other parameters you might be passing

This works now after setting celery.conf.update(result_extended=True) which persists the arguments passed to the task:

def retry_task(task_id):    
    meta=celery.backend.get_task_meta(task_id)
    task = celery.tasks[meta['name']]
    task.apply_async(args=meta['args'], kwargs=meta['kwargs']) #specify any other parameters you might be passing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文