Skip Menu |

This queue is for tickets about the Schedule-Cron CPAN distribution.

Report information
The Basics
Id: 70975
Status: open
Priority: 0/
Queue: Schedule-Cron

People
Owner: Nobody in particular
Requestors: jayk [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.01
Fixed in: (no value)



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 });
The issue seems to be in sub run, in $mainloop. The if block on line 926 looks to see if any entries have changed, and if so it rebuilds the queue. Unfortunately, this kills execution of the current queue processing because rebuild_queue clears $self->{queue}... or so it would seem. I've tried a couple modifications, mainly oriented around only rebuilding the queue at the end of a cycle... but I don't think I quite grok the way it works (or maybe it's just late) because my attempts only kinda work (they solve the first problem, but introduce new ones) Thanks in advance for any help on this issue.