在我的Django项目中,我使用Celery 4 + RabbitMQ。我想在自定义amount_counting
应用程序中运行profile
任务。下一个代码引发错误。怎么解决?似乎芹菜没有看到这个任务。
我用: 芹菜== 4.1.1 Django的== 1.11.5
celery -A EnjoyJumping beat -l info
[2018-06-03 21:03:41,963: INFO/MainProcess] Scheduler: Sending due task amount-counting (profile.tasks.amount_counting)
celery -A EnjoyJumping worker -l info
celery.py:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'EnjoyJumping.settings')
app = Celery('EnjoyJumping')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
settings.py:
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_RESULT_BACKEND = 'amqp://localhost'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Almaty'
CELERY_BEAT_SCHEDULE = {
"amount-counting": {
"task": "profile.tasks.amount_counting",
"schedule": 30.0,
},
}
CELERY_IMPORTS = (
"profile",
)
配置文件/ tasks.py:
from __future__ import absolute_import, unicode_literals
from celery import task
@task()
def amount_counting():
# some code