我遇到了一些芹菜3.1.8,django 1.6.1和Rabbitmq的任务遇到的麻烦。我对当前文档有些困惑,因为我知道不再需要Django-Celery来与Django一起运行芹菜。我觉得我没有正确地运行工人,但是在搜索解决方案和谷歌搜索后,我需要帮助。谁能将我指向正确的方向?
settings.py(不确定我是否需要这个
CELERYBEAT_SCHEDULE = {
'add-every-30-seconds': {
'task': 'tasks.send_test_email',
'schedule': datetime.timedelta(seconds=30)
},
}
我的应用(芹菜.py)
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app',
broker='amqp://',
backend='amqp://',
include=['app.tasks'])
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_TIMEZONE='Europe/Oslo',
)
if __name__ == '__main__':
app.start()
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
定期任务(tasks.py)
from __future__ import absolute_import
from celery.task import periodic_task
import datetime
@periodic_task(run_every=datetime.timedelta(minutes=1))
def send_test_email():
print "This is a periodic task from celery"
在命令行上,我正在执行工人:
celery worker -A app -l info
celery beat
其他一些解决方案是使用@periodic_task
芹菜装饰
from celery.schedules import crontab
@periodic_task(run_every=crontab(minute=0, hour=1))
def my_task():
print 'my_task'