Set up a scheduled job?

后端 未结 24 2553
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 01:13

I\'ve been working on a web app using Django, and I\'m curious if there is a way to schedule a job to run periodically.

Basically I just want to run through the dat

24条回答
  •  太阳男子
    2020-11-22 01:45

    I use celery to create my periodical tasks. First you need to install it as follows:

    pip install django-celery
    

    Don't forget to register django-celery in your settings and then you could do something like this:

    from celery import task
    from celery.decorators import periodic_task
    from celery.task.schedules import crontab
    from celery.utils.log import get_task_logger
    @periodic_task(run_every=crontab(minute="0", hour="23"))
    def do_every_midnight():
     #your code
    

提交回复
热议问题