Like this question (Django - set up a scheduled job) I want to run a regular task within Django.
I'd also really like to bundle it within Django if possible, rather than requiring a cron job. Ideally I'd like to handle the client a Django app that they can plug and play and move across servers, without needing to edit the crontab each time.
So, I'd like some advice. Could I bundle something like the following with Django, and hook into Django's startup process somehow? (pseudocode)
Function secondsUntilNextRun() {
$a = getTimeValue(“Next Friday at 9am”)
$b = getCurrentTimeValue()
Return $a - $b
}
OnStartup {
$timeToSleep = secondsUntilNextRun()
Start Background Thread
}
Background Thread {
Sleep($timeToSleep)
DoEmailReminders()
$timeToSleep = secondsUntilNextRun()
}
And what would be the advantages/disadvantages of doing this versus using cron + a Django management command?
thanks!