periodic task with Django - jenhaoyang/backend_blog GitHub Wiki

範例:

from main_app.celery import app as celery_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'))

@celery_app.task
def test(arg):
    print(arg)

參考:
https://stackoverflow.com/q/41119053