Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

POE to fire off job based on date/time

by sweetblood (Prior)
on Feb 15, 2011 at 19:11 UTC ( [id://888361]=perlquestion: print w/replies, xml ) Need Help??

sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

I’m 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. I’d 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, I’m just stuck trying to come up with a way to fire off this “job” while the other stuff is running. I’m thinking POE is the best solution but my brain is jammed. I’m not looking for someone to code this up, just a nudge in the right direction.
Thanks as always!

Sweetblood

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found