import celery app = celery.Celery('cele', broker='redis://localhost:6379') @app.task def send(message): return message app.conf.beat_schedule = { 'send-every-10-seconds': { 'task': 'cele.send', 'schedule': 10.0, 'args': ('Hello World', ) }, }
from celery import Celery from celery.schedules import crontab app = Celery() @app.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs): # Calls test('hello') every 10 seconds. sender.add_periodic_task(10.0, test.s('hello'), name='add every 10') # Calls test('world') every 30 seconds sender.add_periodic_task(30.0, test.s('world'), expires=10) # Executes every Monday morning at 7:30 a.m. sender.add_periodic_task( crontab(hour=7, minute=30, day_of_week=1), test.s('Happy Mondays!'), ) @app.task def test(arg): print(arg)
from celery.schedules import crontab
c1 = crontab()
c2 = crontab(minute=0, hour=0)
crontab(minute='*/15')
crontab(minute='',hour='', day_of_week='sun')
crontab(minute='*/10',hour='3,17,22', day_of_week='thu,fri')
############启动 celery -A cele beat