简体   繁体   English

Python + Celery手动路由

[英]Python + Celery manual routing

I've been working on getting manual routing set up with Celery, but can't seem to get specific tasks into specific queues. 我一直在使用Celery设置手动路由,但是似乎无法将特定任务放入特定队列中。 Here's what I've got going on so far pretty much: 到目前为止,这是我正在进行的工作:


CELERY_QUEUES = {
    "default": {
        "binding_key": "default"},
    "medium": {
        "binding_key": "medium"},
     "heavy": {
         "binding_key": "heavy"},
      }

with the routes defined like 路线定义如下


CELERY_ROUTES = ({ "tasks.some_heavy_task": {
                   "queue": "heavy",
                   "routing_key": "tasks.heavy"
                  }}, )

and the daemons started like 守护进程开始像


celeryd -l INFO -c 3 -Q heavy

The "some_heavy_task"'s never get run though. 不过,“ some_heavy_task”永远不会运行。 When I remove the routing and just have a default queue I can get them to run. 当我删除路由并只有默认队列时,我可以让它们运行。 What am I doing wrong here, any suggestions? 我在这里做错什么,有什么建议吗?

I created special celeryconfig file for each tasks, all tasks stored in special queue. 我为每个任务创建了特殊的celeryconfig文件,所有任务都存储在特殊队列中。 Here is example: 这是示例:

CELERY_IMPORTS = ('cleaner_on_celery.tasks',)
CELERYBEAT_SCHEDULE = {
    'cleaner': {
        "task": "cleaner_on_celery.tasks.cleaner",
        "schedule": timedelta(seconds=CLEANER_TIMEOUT),
    },
}
CELERY_QUEUES = {
    "cleaner": {"exchange": "cleaner", "binding_key": "cleaner"}
}
CELERY_DEFAULT_QUEUE = "cleaner"

from celeryconfig import *

You can see in the bottom: I import common celeryconfig module. 您可以在底部看到:我导入了常用的celeryconfig模块。 In this case you can start few celeryd instances. 在这种情况下,您可以启动几个celeryd实例。 Also I recommend to use it with supervisord, after creating supervisord.conf file for each task you can easy manage them as: 我也建议将它与supervisor一起使用,在为每个任务创建了supervisor.conf文件之后,您可以轻松地将它们管理为:

supervisorctl start cleaner
supervisorctl stop cleaner

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM