Set up a scheduled job?

后端 未结 24 2550
爱一瞬间的悲伤
爱一瞬间的悲伤 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:44

    One solution that I have employed is to do this:

    1) Create a custom management command, e.g.

    python manage.py my_cool_command
    

    2) Use cron (on Linux) or at (on Windows) to run my command at the required times.

    This is a simple solution that doesn't require installing a heavy AMQP stack. However there are nice advantages to using something like Celery, mentioned in the other answers. In particular, with Celery it is nice to not have to spread your application logic out into crontab files. However the cron solution works quite nicely for a small to medium sized application and where you don't want a lot of external dependencies.

    EDIT:

    In later version of windows the at command is deprecated for Windows 8, Server 2012 and above. You can use schtasks.exe for same use.

    **** UPDATE **** This the new link of django doc for writing the custom management command

提交回复
热议问题