No currently there is no way to tell ServiceLoop() to skip a few seconds to get back in sync. The INTERVAL is rather "sleep this long between actions" than "do this action each N minutes". It was easier to do it that way and I did not care that the action doesn't happen once every ten minutes, but once every ten minutes and one second.
I will add an option to Win32::Daemon::Simple that will instruct ServiceLoop() to tick in even intervals. Please don't hold your breath.
Actually I do have a service that acts as a scheduler and starts different subtasks at different scheduled times (each 30 minutes, at 15:40 each day, at 1:30 each Sunday, etc.) which seems to be close to what you are trying to do.
I guess I should extract that functionality into a module. Win32::Daemon::Extended I guess ;-)
Anyway for now you will need to do something like this:
my $next_time = time()*60;
while(1) {
DoEvents;
sleep(1);
if (time() >= $next_time) {
$next_time += 60;
your_callback();
}
}
(I'll probably do something a little more complex for the ServiceLoop() in "exact" mode to decrease the number of time() calls, but I don't think it matters here.)
HTH, Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature |