我正在使用带有Django-1.11和主管3.3.1的芹菜4.1.0。出于某种原因,当我通过主管运行芹菜工人时,芹菜无法发现应用程序中的任务(在INSTALLED_APPS中列出)。当我从命令行运行芹菜时,会显示任务。例如,当我从命令行运行celery时,输出是:
从命令行运行:
/ home / ubuntu / Env / oba / bin / celery worker -A oba -l DEBUG
- ** ---------- .> transport: amqp://***:**@localhost:***//
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. celery.accumulate
. celery.backend_cleanup
. celery.chain
. celery.chord
. celery.chord_unlock
. celery.chunks
. celery.group
. celery.map
. celery.starmap
. contact.tasks.send_email_to_admin_for_member
. contact.tasks.send_email_to_admin_for_visitor
但是当通过supervisord运行时,芹菜的输出是:
- ** ---------- .> transport: amqp://***:**@localhost:***//
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. celery.accumulate
. celery.backend_cleanup
. celery.chain
. celery.chord
. celery.chord_unlock
. celery.chunks
. celery.group
. celery.map
. celery.starmap
supervisord的配置如下所示:
[program:celery]
command=/home/ubuntu/Env/oba/bin/celery -A oba worker -l DEBUG
environment=PATH="/home/ubuntu/Env/oba/bin"
directory=/home/ubuntu/oba
autostart=true
autorestart=true
startretries=3
stdout_logfile=/var/log/celery/%(program_name)s.log
stdout_logfile_maxbytes=50MB
stderr_logfile=/var/log/celery/%(program_name)s.log
stderr_logfile_maxbytes=50MB
user=celery
numprocs=1
process_name=%(program_name)s-%(process_num)s
有趣的是,在尝试检查已注册的任务时,我看到了:
home / ubuntu / Env / oba / bin / celery -A oba inspect registered
-> celery@ubuntu-512mb-xxx: OK
- empty -
myproject / oba / celery.py中的我的celery.py看起来像这样:
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oba.settings')
from django.conf import settings
app = Celery('oba')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
我在contact / tasks.py中声明了我的任务:
@shared_task
def send_email_to_admin_for_visitor(contactus_visitor_id):
pass
我不确定为什么它无法自动发现任务。有线索吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
我以前遇到过这个问题。我的问题原来是我用来启动celery worker的用户(这里的用户是“ celery”)对我的应用没有正确的访问权限。这意味着用户无法在app文件夹中看到任务。
检查您的应用程序目录的权限并为您的用户授予正确的权限,或者使用已经对您的应用程序目录具有权限的用户启动工作程序,即可解决此问题。