我不能让芹菜正常工作(aws elasticbeanstalk)

时间:2017-03-14 09:38:22

标签: python django celery django-celery amazon-elastic-beanstalk

我正在将django应用程序移动到python3 / django 1.10。该流程的一部分还包括新部署,我们使用AWS EBS。

芹菜任务在迁移之前是可以的,但现在我无法使任务正常工作。

包裹:

...
celery==3.1.23
Django==1.10.6
django-celery==3.2.1
...

的Python:

Python 3.4.3

在supervisor配置中,我添加了一个运行celery的配置:

[program:celeryd-workers]
; Set full path to celery program if using virtualenv
command=/opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4
directory=/opt/python/current/app
user=nobody
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true    
stdout_logfile=/var/log/celery-worker.log
stderr_logfile=/var/log/celery-worker.log
environment=PYTHONPATH="/opt/python/current/app/:",PATH="/opt/python/run/venv/bin/:%(ENV_PATH)s",DJANGO_SETTINGS_MODULE="settings.qa"

[program:celeryd-beat]
; Set full path to celery program if using virtualenv
command=/opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery beat -A app --app=app.celery_app:app --loglevel=DEBUG --workdir=/tmp --pidfile=/tmp/celerybeat.pid -s /tmp/celerybeat-schedule.db
directory=/opt/python/current/app
user=nobody
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true

stdout_logfile=/var/log/celery-beat.log
stderr_logfile=/var/log/celery-beat.log
environment=PYTHONPATH="/opt/python/current/app/:",PATH="/opt/python/run/venv/bin/:%(ENV_PATH)s",DJANGO_SETTINGS_MODULE="settings.qa"

我的celery_app.py非常简单:

from __future__ import unicode_literals, absolute_import

from celery import Celery
from django.conf import settings

app = Celery()

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

配置

在EC2实例上,芹菜的设置为:

BROKER_URL = 'the aws elastic cache redis url'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'

BROKER_TRANSPORT_OPTIONS = {
    'visibility_timeout': 600,
}

BROKER_POOL_LIMIT = 1

CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack']

CELERY_DEFAULT_QUEUE = 'default'
CELERY_QUEUES = {
    'default': {
        'exchange': 'default',
        'exchange_type': 'topic',
        'binding_key': 'tasks.#'
    }
}

CELERY_ALWAYS_EAGER = True

从我检查配置的实例(来自django.conf导入设置),我检查了实例是否可以使用redis-cli连接到redis。

什么不起作用?

基本上如果我运行一个任务,即使是最简单的任务,如芹菜文档中的add(x,y),我也没有在./manage.py celery events中完成任务,我把事件留给了一对夫妇几个小时,我试图从应用程序运行任务,但没有任何反应,似乎卡住了。

 No task selected                                                                                                                                                                                  │
│  Workers online: celery@ip-xx-xx-xx-xx                                                                                                                                                            │
│  Info: events: 2187 tasks:0 workers:1/1
│  Keys: j:down k:up i:info t:traceback r:result c:revoke ^c: quit

奇怪的是,如果我在我的应用程序中的文档中运行此任务:

In [1]: from app.core.tasks import add

In [2]: result = add.delay(2,2)

In [3]: result.get()
Out[3]: 4

结果显示,但我看不到事件中的任何任务,如果我查看celery inspect statistics

...
       "pool": {
            "max-concurrency": 4,
            "max-tasks-per-child": "N/A",
            "processes": [
                11363,
                11364,
                11365,
                11366
            ],
            "put-guarded-by-semaphore": false,
            "timeouts": [
                0,
                0
            ],
            "writes": {
                "all": "",
                "avg": "0.00%",
                "inqueues": {
                    "active": 0,
                    "total": 4
                },
                "raw": "",
                "total": 0
            }
        },
....

似乎没什么用。

当然这个过程正在运行:

[ec2-user@xxx]$ ps aux | grep "celery"
nobody   11350  0.0  3.7 251484 77408 ?        S    08:11   0:01 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery beat -A app --app=app.celery_app:app --loglevel=DEBUG --workdir=/tmp --pidfile=/tmp/celerybeat.pid -s /tmp/celerybeat-schedule.db
nobody   11351  0.1  3.8 247804 79848 ?        S    08:11   0:07 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4
nobody   11363  0.0  3.4 243876 70956 ?        S    08:11   0:00 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4
nobody   11364  0.0  3.4 243876 71024 ?        S    08:11   0:00 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4
nobody   11365  0.0  3.4 243876 71024 ?        S    08:11   0:00 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4
nobody   11366  0.0  3.4 243876 71024 ?        S    08:11   0:00 /opt/python/run/venv/bin/python /opt/python/current/app/manage.py celery worker -A app --app=app.celery_app:app -l DEBUG -c 4

日志:

[ec2-user@xxxx log]$ tail  /var/log/celery-worker.log
[2017-03-14 20:34:45,126: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:34:50,124: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:34:55,125: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:00,124: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:05,125: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:10,124: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:15,125: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:20,124: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:25,125: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2017-03-14 20:35:30,124: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]

芹菜打败了:

[ec2-user@xxxx log]$ tail  /var/log/celery-beat.log
>>>> Testing: False
celery beat v3.1.23 (Cipater) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> redis://qa-redis.xxxx:6379//
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> /tmp/celerybeat-schedule.db
    . logfile -> [stderr]@%DEBUG
    . maxinterval -> now (0s)

你知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

您的设置文件有 CELERY_ALWAYS_EAGER = True 这基本上意味着它将跳过队列并在本地运行任务。因此,您无需看到任何事件即可获得结果。 看看http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_always_eager

我会尝试删除该设置并从那里开始工作。