用芹菜制作的临时队列 [英] Temporary queue made in Celery

查看:21
本文介绍了用芹菜制作的临时队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Celery 与 RabbitMQ 一起使用.最近,我注意到有大量的临时队列.

I am using Celery with RabbitMQ. Lately, I have noticed that a large number of temporary queues are getting made.

所以,我实验发现,当一个任务失败(即一个任务引发异常)时,就会形成一个随机名称的临时队列(如 c76861943b0a4f3aaa6a99a6db06952c),而队列仍然存在.

So, I experimented and found that when a task fails (that is a tasks raises an Exception), then a temporary queue with a random name (like c76861943b0a4f3aaa6a99a6db06952c) is formed and the queue remains.

在 rabbitmqadmin 中找到的临时队列的一些属性如下 -

Some properties of the temporary queue as found in rabbitmqadmin are as follows -

自动删除:真消费者:0耐用:假留言:1messages_ready : 1

auto_delete : True consumers : 0 durable : False messages : 1 messages_ready : 1

每次任务失败(即引发异常)时都会创建一个这样的临时队列.如何避免这种情况?因为在我的生产环境中会形成大量这样的队列.

And one such temporary queue is made everytime a task fails (that is, raises an Exception). How to avoid this situation? Because in my production environment a large number of such queues get formed.

推荐答案

嗯,菲利普就在那儿.以下是我如何解决它的描述.它是 celeryconfig.py 中的一个配置.

Well, Philip is right there. The following is a description of how I solved it. It is a configuration in celeryconfig.py.

正如菲利普所说,我仍在使用 CELERY_BACKEND = "amqp".但除此之外,我现在使用 CELERY_IGNORE_RESULT = True.此配置将确保不会为每个任务都形成额外的队列.

I am still using CELERY_BACKEND = "amqp" as Philip had said. But in addition to that, I am now using CELERY_IGNORE_RESULT = True. This configuration will ensure that the extra queues are not formed for every task.

我已经在使用这个配置,但是当任务失败时,额外的队列就形成了.然后我注意到我正在使用另一个需要删除的配置,即 CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True.这样做的原因是它没有存储所有任务的结果,而只存储错误(失败的任务),因此为失败的任务增加了一个队列.

I was already using this configuration but still when a task fails, the extra queue was formed. Then I noticed that I was using another configuration which needed to be removed which was CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True. What this did that it did not store the results for all tasks but did only for errors (tasks which failed) and hence one extra queue for a task which failed.

这篇关于用芹菜制作的临时队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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