Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Time Drift when using Win32::Daemon::Simple

by Jenda (Abbot)
on Apr 17, 2003 at 15:46 UTC ( [id://251239]=note: print w/replies, xml ) Need Help??


in reply to Time Drift when using Win32::Daemon::Simple

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

Replies are listed 'Best First'.
Re: Re: Time Drift when using Win32::Daemon::Simple
by rah (Monk) on Apr 17, 2003 at 17:49 UTC
    Not sure I follow (been a long couple of days). Do you mean replace the daemon's interval call back with this timing loop? I ran a simple test and it does seem to stay accurate to the second.

    The other approach I had considered was to test for how much the timer had drifted at safe periods, then pause and resume the service to get back on synch. It doesn't elimate the problem, but allows me to specify where it skips ahead to the next minute. This would eliminate the risk of my missing a significant time period.

      1. Yes. Just replace the

      ServiceLoop(\&callback);
      with the loop.

      2. I don't think I follow, you mean that your callback would wait 59 seconds in case the time drifted to put it back in sync? Well you can do that. Apart from the fact that you will not be able to stop the service (via the Service Manager) during those 59 seconds you are safe.

      Jenda
      All those who understood the topic I just elucidated, please verticaly extend your upper limbs.
         -- Ted Goff

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-12-12 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (65 votes). Check out past polls.