|No such thing as a small change|
Scheduling without cron or modulesby Samn (Monk)
|on Aug 10, 2003 at 00:26 UTC||Need Help??|
Samn has asked for the wisdom of the Perl Monks concerning the following question:
Heya monks. I'd like to write a scheduling agent to run scheduled tasks for my entirely Perl driven community site. I don't want to use Cron or any modules, for a good reason.
In this scheduling agent, I want to assign multiple events to times, obviously run them on time, and then reset the time for that event's next run. Precision isn't important, only reliability.
I could store the event schedule in a file, or the database, and read it in every time the engine is started/the website receives a hit. This would fire something like 80,000 times a day (looking for four or five events) and be very wasteful.
I had the other idea to write a separate script ("monitor.cgi") that would load the list of events into memory on start, and then begin a sleep, check, sleep cycle. Meanwhile, the main engine would check every hit to just make sure monitor.cgi is still up and running. In other words, the monitor would always be running.
Which of these options is the biggest drain? It seems obvious, but I don't know what's going on with the hardware when a script is sleeping and try to avoid assumptions.
Are there any other solutions? If the monitor idea sounds like a good one, I'll have One More Question™ regarding how to check that a particular script is running.
Thanks in advance to any solutions, advice or scolding!