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

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!


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
[erix]: choroba I believe you ;)
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)
[perldigious]: I train for long portaging/rowing trips by carrying my kayak to the river about a half mile from my house 2-3 times a week depending on weather... but due to a lingering winter, I haven't had long to train this year.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-05-24 12:56 GMT
Find Nodes?
    Voting Booth?