Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging scheduled time with Schedule::Cron
    text
    copied!<p>I'm writing a script in Perl that needs to run at the same time every night, except sometimes that time needs to change. I found <a href="http://search.cpan.org/perldoc?Schedule::Cron" rel="nofollow">Schedule::Cron</a> on CPAN, and it does what I want it to do. According to the documentation for the run method,</p> <blockquote> <p>nofork => 1</p> <p>Don't fork when starting the scheduler. Instead, the jobs are executed within current process. In your executed jobs, you have full access to the global variables of your script and hence might influence other jobs running at a different time.</p> </blockquote> <p>Which is what I want to do, but it is not doing. Whenever I examine the global variables memory location, they are the same, but the value is not changed when the the task starts.</p> <p>I've run this on both Windows and Linux, and I've had someone else look at the code to see if my logic was correct. What do I need to do to keep the changes to the global variables.</p> <pre><code>use warnings; use strict; use Schedule::Cron; use Time::localtime; use constant { EVERY_DAY_10PM =&gt; '* * * * * 4,16,28,40,52', EVERY_DAY_NOON =&gt; '* * * * * 0,12,24,36,48', EVERY_DAY_2AM =&gt; '* * * * * 7,19,31,43,55' }; ############GLOBAL VARIABLES############ our $cron = new Schedule::Cron(\&amp;runUpdate); our $cronId; our $updateTimeDirty = 0; ############END GLOBAL VARIABLES############ ############MAIN PROGRAM BODY############ $cronId = $cron-&gt;add_entry(EVERY_DAY_10PM);#defaults to \&amp;runUpdate $cron-&gt;add_entry(EVERY_DAY_NOON, \&amp;changeTime); $cron-&gt;run(no_fork =&gt; 1); ############END MAIN PROGRAM BODY############ sub changeTime { our $cron; our $cronId; our $updateTimeDirty; print "updateTimeDirty is $updateTimeDirty\n"; print "udpateTimeDirty location: " . \$updateTimeDirty . "\n"; print "cron object: " . \$cron . "\n"; if ($updateTimeDirty) { my $cronEntry = $cron-&gt;get_entry($cronId); $cronEntry-&gt;{time} = EVERY_DAY_2AM; $cron-&gt;update_entry($cronId, $cronEntry); } print "\n"; } sub runUpdate { our $updateTimeDirty; $updateTimeDirty = 1; print "Updating at " . localtime()-&gt;sec . " ($updateTimeDirty)\n\n"; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload