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
local now = date();
timer_t = now;
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?
That looks fine, though obviously as you note if you did run out of wakeups it would fail. Am going to try and replicate with just the above code - have you managed to replicate with this minimal set, or do you only see the problem with your full code?
Yep, I’m familiar with running out of wakeups, so I’ve recoded to dramatically reduce the number that I use in other parts of my agent code. I would have also expected an error message in the console if it occurs again.
The problem is difficult to replicate. Hence, I’m raising it here. My code is littered with debug hooks, trying to capture the moment when the timer stops. I’ve seen it stop updating but I haven’t been successful in understanding why.
No, I haven’t tried it with the minimal set. I’m running a few dozen test imps, all with a one minute timer. Many of them POST to web services once a minute. I notice it when the POSTs stop arriving. When I check the agents I find that the 1 minute timer is no longer running. There are no errors/events to indicate what went wrong, just no wakeup.
I will set up a couple of imps with a minimal 1 minute timer. I will also replace the housekeeping function with one that fails randomly and see if that kills the timer.
The housekeeping work I actually do on each minute can be many many hundreds of lines of code, which is why I call imp.wakeup before it rather than afterwards.