In order to keep my agent in order, I’m calling a variety of housekeeping routines every minute. I want it aligned closely to real time, so I watch the clock and call my housekeeping when the minute value from date() changes. This seems to work pretty well, except for the times where it doesn’t. If I run imps for hours/days they will regularly call the one minute housekeeping routine and then inexplicably stop. Everything else continues to run on the agent. There are no errors or warning messages.
I am aware of the 20 timer limit on the agent and check for null every time I call imp.wakeup(). Here is a simplified version of my routine (with error checking removed):
`// generate a regular 1 minute event
function timer_trigger(){
local now = date();
if (now.min!=timer_t.min){
timer_t = now;
imp.wakeup(59-timer_t.sec,timer_trigger);
doHousekeeping();
}
else
imp.wakeup(0.1,timer_trigger);
}
timer_t<-date();
imp.wakeup(59-timer_t.sec,timer_trigger)`
The routine above will call itself regularly as it approaches the minute, in an attempt to get within 0.1s of the moment.
I struggling to see what could possibly stop it dead in its tracks. If doHousekeeping() were to hit an error (it doesn’t seem to), I assume that the preceding imp.wakeup would still be valid, right?
Are there any other reasons why a timer might stop?