I'm searching for a method to make a def to execute at a time value when I run the server... Example once per day. One solution is to use Celery but i don't want to use it only for a simple def... Any suggestion? I'm using windows. Thanks!
Asked
Active
Viewed 32 times
0
Florin
- 264
- 2
- 12
-
Does this answer your question? [Python Equivalent of setInterval()?](https://stackoverflow.com/questions/2697039/python-equivalent-of-setinterval) – aviya.developer Feb 17 '20 at 17:23
-
can I use that method combined with `py manage.py runserver`? – Florin Feb 17 '20 at 17:30
2 Answers
0
There are certainly several possibilities, so this is just one of many solutions:
We use Unix cron jobs or Kubernetes cron jobs for this which call:
./manage.py <the command>
(or call docker exec .... manage.py <the command>)
You should make sure that your logs go whereever you need them to monitor the cron job.
Note: there was a similar question I've answered with more details: https://stackoverflow.com/a/52778625/621690
Risadinha
- 14,638
- 2
- 78
- 87
-
But, he use windows... maybe can write a command, but with Task Scheduler... – kaajavi Feb 17 '20 at 17:43
0
Look in to using the Windows Task Scheduler to run your django task via manage.py. You can schedule it once a day from here or as often as you need.
https://docs.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page
Use the simplest solution to solve your problem until you require a more complex solution.
Josh J
- 6,653
- 3
- 21
- 44