0

I wrote small django website that read the data from data base and show that data in a table. (Database will be filled by making the request to an external API. )

Now my problem is that I need to make the request every 5 minutes to API and get the last 5 mins data and store them in the data base and at the same time update my table to show last 5 mins data.

I have read about job scheduler but I did not get how I can perform it. First of all is an scheduler such as celery is a good solution for this problem? and would be helpful for me if you can guide me how would be the approach to solve this?

user2091416
  • 77
  • 2
  • 10
  • Welcome to SO: you may want to read [ask] and [mcve]. As for your question, you may want to read ​https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python. – boardrider Sep 29 '17 at 14:04

1 Answers1

0

A simple solution I have used in the past is to write a django custom command and then have a cronjob run that command at whatever interval you would like.

Django commands: https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/

Milkboat
  • 179
  • 1
  • 6
  • Thanks. So cornjob should run on my view.py and everything such as fetching data and storing to data base and updating table should be a command! Is that correct? – user2091416 Sep 28 '17 at 15:38
  • I would write the code that's in your view as the custom command, or whatever logic you want to do every 5 mins. And then the cronjob would call 'python manage.py command_name' every 5 mins. – Milkboat Sep 28 '17 at 15:42