diff options
author | Peter Palfrader <peter@palfrader.org> | 2002-08-23 07:54:53 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2002-08-23 07:54:53 +0000 |
commit | 8c90f3f18a632d44c82d18626fe390bc5d69d903 (patch) | |
tree | 9e22e0f0dca49044420d58e1bc99393bf61b595d /Echolot/Scheduler.pm | |
parent | 7c9b666ef12fd6fbb246d3df014271706e2df9f6 (diff) |
Scheduler fixes (inserted jobs for one time processing got requeued over and over again according to their interval).
Diffstat (limited to 'Echolot/Scheduler.pm')
-rw-r--r-- | Echolot/Scheduler.pm | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Echolot/Scheduler.pm b/Echolot/Scheduler.pm index df245c8..1331aff 100644 --- a/Echolot/Scheduler.pm +++ b/Echolot/Scheduler.pm @@ -1,7 +1,7 @@ package Echolot::Scheduler; # (c) 2002 Peter Palfrader <peter@palfrader.org> -# $Id: Scheduler.pm,v 1.11 2002/07/22 01:28:21 weasel Exp $ +# $Id: Scheduler.pm,v 1.12 2002/08/23 07:54:53 weasel Exp $ # =pod @@ -62,19 +62,21 @@ sub add($$$$$) { order => $ORDER++ }; - $self->schedule($name); + $self->schedule($name, 1); return 1; }; -=item B<schedule> (I<name>, I<for>) +=item B<schedule> (I<name>, I<reschedule>, [ I<for>, [I<arguments>]] ) Schedule execution of I<name> for I<for>. If I<for> is not given it is calculated -from I<interval> and I<offset> passed to B<new>. +from I<interval> and I<offset> passed to B<new>. if I<reschedule> is set +the task will be rescheduled when it's done (according to its interval). +You may also give arguments to passed to the task. =cut -sub schedule($$;$$) { - my ($self, $name, $for, $arguments) = @_; +sub schedule($$$;$$) { + my ($self, $name, $reschedule, $for, $arguments) = @_; (defined $self->{'tasks'}->{$name}) or cluck("Task $name is not defined"), @@ -99,7 +101,8 @@ sub schedule($$;$$) { start => $for, order => $self->{'tasks'}->{$name}->{'order'}, name => $name, - arguments => $arguments + arguments => $arguments, + reschedule => $reschedule }; @{ $self->{'schedule'} } = sort { $a->{'start'} <=> $b->{'start'} or $a->{'order'} <=> $b->{'order'} } @@ -146,8 +149,8 @@ sub run($) { print "Running $name at ".(time())." (scheduled for $now)\n" if Echolot::Config::get()->{'verbose'}; last if ($what eq 'exit'); &$what( $now, @{ $task->{'arguments'} } ); - $self->schedule($name, $now + $self->{'tasks'}->{$name}->{'interval'}) if - ($self->{'tasks'}->{$name}->{'interval'} > 0); + $self->schedule($name, 1, $now + $self->{'tasks'}->{$name}->{'interval'}) if + ($task->{'reschedule'} && $self->{'tasks'}->{$name}->{'interval'} > 0); (defined $self->{'schedule'}->[0]) or cluck("Scheduler is empty"), |