Answer the question
In order to leave comments, you need to log in
How in Django to automatically fill the model with some periodicity?
There is a need to periodically (for example, once every 5 seconds) add data to the model. So far, only a way comes to mind with the help of a custom manage.py command, which is run by cron.
That is, we pull "manage.py doit" with the crown, the script accesses the source via the API, receives the data, and if they are different from the existing ones, then updates / adds data to the model.
This method is not entirely satisfactory, because. it will be necessary to dynamically change the time of updating data and, possibly, adding new sources.
Are there any other ways that can help solve this problem?
Answer the question
In order to leave comments, you need to log in
Cron is not suitable for tasks that need to be performed every few seconds. Periodicity maximum 1 minute. Of course, you can write all sorts of crutches, but I advise you to look in the direction of www.celeryproject.org
It will be possible to run a task, in the course of its work, calculate the time after which you need to execute it again, accurate to the second.
Just write a script in any language like python and keep it running all the time. And from this script, already pull the data and directly look into the database or somewhere else. In the same place, the time will be dynamically calculated, after how much to check and fall asleep again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question