如何摆脱仍在Celery / RabbitMQ队列中的遗留任务? [英] How can I get rid of legacy tasks still in the Celery / RabbitMQ queue?

查看:266
本文介绍了如何摆脱仍在Celery / RabbitMQ队列中的遗留任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Django + Celery + RabbitMQ。修改了一些任务名称后,即使从Django Celery Beat的Periodic task表中删除了使用此密钥的任务并重新启动Celery worker之后,我也开始收到未注册任务 KeyErrors。他们坚持,甚至在使用--purge选项运行

I am running Django + Celery + RabbitMQ. After modifying some task names I started getting "unregistered task" KeyErrors, even after removing tasks with this key from the Periodic tasks table in Django Celery Beat and restarting the Celery worker. They persist even after running with the --purge option.

如何摆脱它们?

推荐答案

要清除这些任务中的最后一个,您可以使用其旧的方法标头重新实现它们,但不添加逻辑。

To flush out the last of these tasks, you can re-implement them with their old method headers, but no logic.

例如,如果您删除了原始方法,并且现在出现错误

For example, if you removed the method original and are now getting the error

[ERROR/MainProcess] Received unregistered task of type u'myapp.tasks.original'

的未注册任务

只需重新创建原始方法,如下所示:

Just recreate the original method as follows:

task.py

@shared_task
def original():
    # keep legacy task header so that it is flushed out of queue
    # FIXME: this will be removed in the next release
    pass

在每种环境中运行此版本后,将处理所有剩余任务(不执行任何操作)。确保已将它们从定期任务表中删除,并且不再被调用。然后,您可以在下一次部署之前删除该方法,并且该问题不会再次发生。

Once you have run this version in each environment, any remaining tasks will be processed (and do nothing). Ensure that you have removed them from your Periodic tasks table, and that they are no longer being invoked. You can then remove the method before your next deployment, and the issue should no recur.

这仍然是一种解决方法,因此最好能够分别查看和删除任务

This is still a workaround, and it would be preferable to be able to review and delete the tasks individually.

这篇关于如何摆脱仍在Celery / RabbitMQ队列中的遗留任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆