[英]celery task routing with CELERY_ROUTES not working with task subclasses
I am using celery 3.0.20 and I have difficulties getting celery tasks to work with different queues. 我使用的是celery 3.0.20,我很难让celery任务与不同的队列一起工作。
My celery workers are launched with the queue configuration 我的芹菜工人使用队列配置启动
-Q:w1 default -Q:w2 longrunning
The Django settings contains the following celery config: Django设置包含以下celery配置:
CELERY_QUEUES = (
Queue('default', Exchange('default'), routing_key='default'),
Queue('longrunning', Exchange('longrunning'), routing_key='longrunning'),
)
CELERY_DEFAULT_QUEUE = 'default'
CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'
CELERY_DEFAULT_ROUTING_KEY = 'default'
CELERY_ROUTES = ({'mytasks.task_a.run': {
'queue': 'longrunning',
'routing_key': 'longrunning'
}},
So far, so good. 到现在为止还挺好。 All tasks go by default in the
default
queue, and task_a
goes into the long-running queue. 默认情况下,所有任务都进入
default
队列,而task_a
进入长期运行的队列。
The task_a
module is implemented as follows: task_a
模块的实现如下:
from celery import task
@task
def run():
# do some task work
Now, I have the problem that a different task is implemented as a class inheriting from celery.Task
: 现在,我遇到的问题是,一个不同的任务被实现为从
celery.Task
继承的类:
from celery import Task
class AnotherTask(Task):
def run(self, *args, **kwargs):
# do some task work
When the AnotherTask
class now resides in task_b
module, I cannot make this task to be executed in the longrunning
queue: I tried adding it to CELERY_ROUTES
in different varieties, none of them worked: 当
AnotherTask
类现在驻留在task_b
模块中时,我无法使该任务在task_b
longrunning
队列中执行:我尝试将其添加到不同品种的CELERY_ROUTES
中,但没有一个起作用:
{'mytasks.task_b': {
'queue': 'longrunning',
'routing_key': 'longrunning'
}}
- -
{'mytasks.task_b.AnotherTask': {
'queue': 'longrunning',
'routing_key': 'longrunning'
}}
- -
{'mytasks.task_b.AnotherTask.run': {
'queue': 'longrunning',
'routing_key': 'longrunning'
}}
I also tried to switch to default exchange type 'topic'
, but that didn't work either. 我还尝试切换到默认交换类型
'topic'
,但这也不起作用。
Any hints how to get the task in class AnotherTask
to be executed in the longrunning
queue? 有什么提示如何使类
AnotherTask
的任务在AnotherTask
longrunning
队列中执行吗?
OK, I found the problem. 好的,我发现了问题。
It was due to the fact that all other tasks, ending up in the longrunning
queue, where started regularly with celerybeat . 这是由于所有其他任务最终都排在了长时间
longrunning
队列中,并以celerybeat定期开始。 The new task was started from the web environment. 新任务是从Web环境开始的。 And the celerybeat settings imported the settings containing the
CELERY_ROUTES
dict, the web environment settings did not. 并且celerybeat设置导入了包含
CELERY_ROUTES
字典的设置,而Web环境设置则没有。 Ugh! 啊!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.