我创建了芹菜任务,它应该在第0分钟开始每小时,但它不会运行。做错了什么?
芹菜from __future__ import absolute_import, unicode_literals
import os
import pytz
from celery import Celery
from datetime import datetime
from celery.schedules import crontab
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app', broker='amqp://rabbit:5672')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
sender.add_periodic_task(crontab(minute=0, hour='0,1,2,3,4,5,6,7,8,9,10,11,12, \
13,14,15,16,17,18,19,20,21,22,23,24'),
task.s())
@app.task
def task():
#any code
在终端中,我看到此信息,但任务未运行
[2018-05-09 19:05:16,275: INFO/Beat] beat: Starting...
答案 0 :(得分:0)
尝试将您的任务代码更改为以下内容:
from celery.task import periodic_task
from celery.schedules import crontab
@periodic_task(
run_every=(crontab(minute='*/60')),
name="task_name")
def run_some_task():
'''some code'''