from celery import Celery from datetime import timedelta app = Celery('gx', broker='redis://localhost:6379/1') app.conf.update( CELERYBEAT_SCHEDULE={ 'perminute': { 'task': 'gx.add', 'schedule': timedelta(seconds=5), 'args': (1, 2) } } ) @app.task def add(a, b): print(a+b)
先启动worker:celery -A proj worker -l info -f=test.log (-f指定的是日志输出位置)
然后启动beat:celery -A proj beat
beat发起定时任务worker执行定时任务