django / celery多个队列不占用任何任务

时间:2018-09-17 06:43:04

标签: django python-3.x celery django-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

它不起作用。这里有一些屏幕截图

first_queue worker running
second_queue worker running
What happens when I call them
But tasks are not performing

我希望有人能帮助我。 预先感谢

1 个答案:

答案 0 :(得分:0)

根据目录结构,您已经显示S(m + 1)是它自己的应用程序,应该在开始时声明不包含library(knitr) df <- data.frame(Count = c(2, 30, 1, 2, 8, 1, 1), Proportion = c(4, 67, 2, 4, 18, 2, 2)) kable( t(df), col.names = c( "ENT", "General Surgery", "Neurosurgery", "Ophthalmology", "Orthopedic", "PM&R", "Urology" ), caption = "Professors by specialty", row.names = T ) | | ENT| General Surgery| Neurosurgery| Ophthalmology| Orthopedic| PM&R| Urology| |:----------|---:|---------------:|------------:|-------------:|----------:|----:|-------:| |Count | 2| 30| 1| 2| 8| 1| 1| |Proportion | 4| 67| 2| 4| 18| 2| 2| ,例如

mailer