Subject: | Adding entries causes loop to terminate, tasks not to run. |
When running actions that modify the scheduler (using add_entry or delete_entry) any action
that should have been executed in the same cycle are never run.
In other words, suppose you have task 1 and task 2 set to run at the same time. If task1 adds a
new entry to the schedule, task 2 will not get run.
I have attached a sample script that demonstrates the behavior.
Subject: | schedule_eater_test.pl |
#!/usr/bin/perl
use Schedule::Cron;
use Data::Dumper;
sub dostuff {
print "first task\n";
}
sub do_other_stuff {
print "other task\n";
}
# Create new object with default dispatcher
my $scheduler = Schedule::Cron->new( sub {
warn "unknown action";
},
catch => 1,
nofork => 1,
);
my $other = sub { do_other_stuff(@_); };
my $tasknum = 0;
my $do = sub { dostuff(@_);
if ($tasknum < 2) {
print "adding something\n";
my $string = "task" . $tasknum ."\n";
$scheduler->add_entry("* * * * * 0,10,20,30,40,50", { subroutine => sub { print $string; }});
$tasknum++;
}
};
## this entry will work fine, as it is off by a second.
#$scheduler->add_entry("* * * * * 01,11,21,31,41,51", { subroutine => $do });
## this entry will cause the new tasks not to run.
$scheduler->add_entry("* * * * * 00,10,20,30,40,50", { subroutine => $do });
$scheduler->add_entry("* * * * * 00,10,20,30,40,50", { subroutine => $other });
$scheduler->run({ nofork => 1 });