简体   繁体   中英

How to perform a specific task in django automatically after a fixed interval of time?

Lets say I have a database model in Django which stores top 100 songs. This data comes from an api.

The problem is that the song ranking may change from time to time [30 minutes/ 1 hour].

I wish to implement a method in the web app such that it automatically runs a particular function in python [ which updates the database by sending api requests] every 10 minutes , whether there is a user online or not.

How can I do this?

You can use Celery for this, but it is probably overkill if you just have simple task. http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html

A simple solution would be to create a django management task wich update the song raking and call it with a cron every ten minutes.

related answere : django scheduled job

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM