好吧,伙计们,这让我发疯了。我已经为此工作了一整天,但无法让它工作!
我的芹菜项目结构是这样的:
# celery.py
from celery.schedules import crontab
from celery import Celery
celery = Celery('scheduler.celery',
include=['scheduler.tasks'])
celery.config_from_object('celeryconfig')
和:
# tasks.py
from scheduler.celery import celery
@celery.task
def test():
do_something()
和:
# celeryconfig.py
from celery.schedules import crontab
CELERYBEAT_SCHEDULE = {
'test-cron': {
'task': 'tasks.test',
'schedule': crontab(minute='*/1'),
},
}
# CELERY_IMPORTS = ('tasks', )
BROKER_URL = 'redis://localhost:6379/0'
所有文件都在projects/scheduler/
文件夹下。
当我启动celeryd
服务时,我可以看到它正在运行并连接到我的代理,但是当我启动celerybeat
服务时,我可以在日志中看到消息:Received unregistered task of type 'tasks.test'
.
如果我取消注释CELERY_IMPORTS
常量(如 SO 中的许多答案中所建议的那样),celeryd
服务甚至都不会启动!实际上,它输出OK
但使用ps ef | grep celery
我可以看到它没有运行。
我的守护进程 conf 文件如下所示:
# Name of nodes to start
CELERYD_NODES="w1"
# Where to chdir at start.
CELERYD_CHDIR="/home/me/projects/scheduler/"
# Extra arguments to celeryd
CELERYD_OPTS="--time-limit=300 --concurrency=4"
# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Workers should run as an unprivileged user.
CELERYD_USER="celery"
CELERYD_GROUP="celery"
# Extra arguments to celerybeat
CELERYBEAT_OPTS="--schedule=/var/run/celerybeat-schedule"
任何帮助是极大的赞赏。