Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

POE to fire off job based on date/time

by sweetblood (Prior)
on Feb 15, 2011 at 19:11 UTC ( #888361=perlquestion: print w/replies, xml ) Need Help??
sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

Im using POE for a windows service that utilizes POE::Component::DirWatch::Object for transferring data. This has been working really well for several years now. I now need to add a process to run a MS SQL script at the start of every week and then transfer the resulting file. Id prefer to keep the process in this service and not create a new service to create the data file then use this service to transfer the file, Im just stuck trying to come up with a way to fire off this job while the other stuff is running. Im thinking POE is the best solution but my brain is jammed. Im not looking for someone to code this up, just a nudge in the right direction.
Thanks as always!


Replies are listed 'Best First'.
Re: POE to fire off job based on date/time
by rcaputo (Chaplain) on Feb 16, 2011 at 02:36 UTC

    If the weekly task is relatively isolated, start another POE::Session to do it. Something like this may be sufficient if do_that_thing() doesn't take too long.

    POE::Session->create( inline_states => { _start => sub { my $next_unix_time = calculate_when(); $_[KERNEL]->alarm(weekly_task => $next_unix_time); }, weekly_task => { do_that_thing(); my $next_unix_time = calculate_when(); $_[KERNEL]->alarm(weekly_task => $next_unix_time); }, }, );

    If do_that_thing() takes too long, then it may need to involve system(1,"command"). See perlport for discussion of system(1,"command") on MSWin32. For best results, use POE::Kernel's sig_child() to detect when the command has ended.

    And a word about fork() in POE on Windows. If you plan to do anything more than system(1,"command") in the "subprocess", then you should check out POE's Github repository for pre-release iThread-safety fixes. As you may be aware, fork() on MSWin32 is implemented in terms of iThreads, so modules must be iThread-safe to fork() there.

Re: POE to fire off job based on date/time
by kirillm (Friar) on Feb 17, 2011 at 08:26 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888361]
Approved by planetscape
Front-paged by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-02-22 02:10 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.