<?xml version="1.0" encoding="windows-1252"?>
<node id="888437" title="Re: POE to fire off job based on date/time" created="2011-02-15 21:36:06" updated="2011-02-15 21:36:06">
<type id="11">
note</type>
<author id="36709">
rcaputo</author>
<data>
<field name="doctext">
&lt;p&gt;If the weekly task is relatively isolated, start another [mod://POE::Session] to do it.  Something like this may be sufficient if do_that_thing() doesn't take too long.&lt;/p&gt;

&lt;code&gt;
POE::Session-&gt;create(
  inline_states =&gt; {
    _start =&gt; sub {
      my $next_unix_time = calculate_when();
      $_[KERNEL]-&gt;alarm(weekly_task =&gt; $next_unix_time);
    },
    weekly_task =&gt; {
      do_that_thing();
      my $next_unix_time = calculate_when();
      $_[KERNEL]-&gt;alarm(weekly_task =&gt; $next_unix_time);
    },
  },
);
&lt;/code&gt;


&lt;p&gt;If do_that_thing() takes too long, then it may need to involve system(1,"command").  See [doc://perlport] for discussion of system(1,"command") on MSWin32.  For best results, use [mod://POE::Kernel]'s sig_child() to detect when the command has ended.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://github.com/rcaputo/poe"&gt;POE's Github repository&lt;/a&gt; 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.&lt;p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-36709"&gt;
&lt;p&gt;&lt;tt&gt;-- &lt;br&gt;&lt;a href="http://search.cpan.org/~rcaputo/"&gt;Rocco Caputo&lt;/a&gt; - &lt;a href="http://poe.perl.org/"&gt;http://poe.perl.org/&lt;/a&gt; - &lt;a href="irc://irc.perl.org/poe"&gt;irc://irc.perl.org/poe&lt;/a&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
888361</field>
<field name="parent_node">
888361</field>
</data>
</node>
