Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

POE to fire off job based on date/time

by sweetblood (Parson)
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!

Sweetblood

Comment on POE to fire off job based on date/time
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888361]
Approved by planetscape
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-07-23 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (140 votes), past polls