跳转至

Celery学习笔记

定时任务, on_after_configure 和 on_after_finalize区别

on_after_configure

Signal sent after app has prepared the configuration.

on_after_finalize

Signal sent after app has been finalized.

# xxx/tasks.py

from --- import celery_app  # celery_app在其他文件中定义, 

# 所以这里需要用on_after_finalize而不是on_after_configure?
@celery_app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
    # 每10分钟调用一次
    sender.add_periodic_task(60, share_celery_status_update.s(), name='check_share_status')


@celery_app.task
def share_celery_status_update():

To start the celery beat service:

celery -A proj beat --loglevel=info

celery -A proj beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler