我有一个使用celery==4.2.1,redis==2.10.6和redis-server=4.0.9的Django 2.0.5应用程序。当我启动celery worker时,会得到以下输出:
-------------- celery@octopus v4.2.1 (windowlicker)
---- **** -----
--- * *** * -- Linux-4.18.16-surface-linux-surface-x86_64-with-Ubuntu-18.04-bionic 2018-10-31 17:33:50
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: MemorabiliaJSON:0x7fd6c537b240
- ** ---------- .> transport: amqp://guest:**@localhost:5672//
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
但是在我的Django设置中,我有以下内容:
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_IMPORTS = ('memorabilia.tasks',
'face_recognition.tasks',
)
我的 celery.py 文件如下:
# http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.apps import apps
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MemorabiliaJSON.settings.tsunami')
app = Celery('MemorabiliaJSON')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])
相同的代码(通过我的git服务器共享)在我的开发机上运行,尽管redis服务器有点旧 - v=2.8.4。开发机是Ubunutu 14.04,笔记本电脑是Ubuntu 18.04。我所说的“运作正常”是指这是我开发机上的celery输出:
-------------- celery@tsunami v4.2.1 (windowlicker)
---- **** -----
--- * *** * -- Linux-4.4.0-138-generic-x86_64-with-Ubuntu-14.04-trusty 2018-10-31 17:38:09
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: MemorabiliaJSON:0x7f356e024c18
- ** ---------- .> transport: redis://localhost:6379//
- ** ---------- .> results: redis://localhost:6379/
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
我该如何让celery读取除了celery.py之外的django配置文件呢?
谢谢!
Mark