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.
|