django/celery 多个队列不消耗任何任务
django/celery multiple queues not consuming any task
我是 celery 和 django 的新手
在我的 celery 设置中,当我在没有任何队列的情况下调用任务时,它可以与多个工作人员完美配合。但是当我指定队列时,工作人员不会消耗任何东西
我有一个名为 example 的项目
这里的结构
├── example
│ ├── celery.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── mailer
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ └── __init__.cpython-36.pyc
│ ├── models.py
│ ├── tasks.py
│ ├── tests.py
│ └── views.py
└── manage.py
在settings.py
(队列设置)
# ==============================
# CELERY SETTINGS
# ==============================
CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_ROUTES = {
'example.mailer.tasks.first_task': {'queue': 'first_queue'},
'example.mailer.tasks.second_task': {'queue': 'second_queue'},
}
还有我的mailer/tasks.py
@shared_task
def first_task():
for i in tqdm(range(100000000)):
pass
return "First task finished"
@shared_task
def second_task():
for i in range(100000000):
print(i,'Second Task')
return "Second task finished"
有了这个,当我 运行 工人喜欢
celery -A example worker -l info -c 4 -n worker1
celery -A example worker -l info -c 2 -n worker2
它运行完美,但当我尝试时
celery -A example worker -l info -c 2 -n worker1 -Q first_queue
celery -A example worker -l info -c 2 -n worker2 -Q second_queue
这不是working.Here一些屏幕截图
first_queue worker running
second_queue worker running
What happens when I call them
But tasks are not performing
我希望有人能帮助我。
提前致谢
根据您显示的目录结构,mailer
是它自己的应用程序,应该在开头声明时不带 example
,例如
CELERY_ROUTES = {
'mailer.tasks.first_task': {'queue': 'first_queue'},
'mailer.tasks.second_task': {'queue': 'second_queue'},
}
我是 celery 和 django 的新手 在我的 celery 设置中,当我在没有任何队列的情况下调用任务时,它可以与多个工作人员完美配合。但是当我指定队列时,工作人员不会消耗任何东西
我有一个名为 example 的项目 这里的结构
├── example
│ ├── celery.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── mailer
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ └── __init__.cpython-36.pyc
│ ├── models.py
│ ├── tasks.py
│ ├── tests.py
│ └── views.py
└── manage.py
在settings.py (队列设置)
# ==============================
# CELERY SETTINGS
# ==============================
CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_ROUTES = {
'example.mailer.tasks.first_task': {'queue': 'first_queue'},
'example.mailer.tasks.second_task': {'queue': 'second_queue'},
}
还有我的mailer/tasks.py
@shared_task
def first_task():
for i in tqdm(range(100000000)):
pass
return "First task finished"
@shared_task
def second_task():
for i in range(100000000):
print(i,'Second Task')
return "Second task finished"
有了这个,当我 运行 工人喜欢
celery -A example worker -l info -c 4 -n worker1
celery -A example worker -l info -c 2 -n worker2
它运行完美,但当我尝试时
celery -A example worker -l info -c 2 -n worker1 -Q first_queue
celery -A example worker -l info -c 2 -n worker2 -Q second_queue
这不是working.Here一些屏幕截图
first_queue worker running
second_queue worker running
What happens when I call them
But tasks are not performing
我希望有人能帮助我。 提前致谢
根据您显示的目录结构,mailer
是它自己的应用程序,应该在开头声明时不带 example
,例如
CELERY_ROUTES = {
'mailer.tasks.first_task': {'queue': 'first_queue'},
'mailer.tasks.second_task': {'queue': 'second_queue'},
}