From 8c90f3f18a632d44c82d18626fe390bc5d69d903 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 23 Aug 2002 07:54:53 +0000 Subject: Scheduler fixes (inserted jobs for one time processing got requeued over and over again according to their interval). --- Echolot/Commands.pm | 10 +++++----- Echolot/Scheduler.pm | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'Echolot') diff --git a/Echolot/Commands.pm b/Echolot/Commands.pm index c0a6b59..6c6901c 100644 --- a/Echolot/Commands.pm +++ b/Echolot/Commands.pm @@ -1,7 +1,7 @@ package Echolot::Commands; # (c) 2002 Peter Palfrader -# $Id: Commands.pm,v 1.9 2002/07/17 17:53:44 weasel Exp $ +# $Id: Commands.pm,v 1.10 2002/08/23 07:54:53 weasel Exp $ # =pod @@ -68,13 +68,13 @@ sub processCommands($) { } elsif ($command eq 'set') { Echolot::Globals::get()->{'storage'}->set_stuff(@args); } elsif ($command eq 'getkeyconf') { - Echolot::Globals::get()->{'scheduler'}->schedule('getkeyconf', time(), \@args ); + Echolot::Globals::get()->{'scheduler'}->schedule('getkeyconf', 0, time(), \@args ); } elsif ($command eq 'buildstats') { - Echolot::Globals::get()->{'scheduler'}->schedule('buildstats', time() ); + Echolot::Globals::get()->{'scheduler'}->schedule('buildstats', 0, time() ); } elsif ($command eq 'buildkeys') { - Echolot::Globals::get()->{'scheduler'}->schedule('buildkeys', time() ); + Echolot::Globals::get()->{'scheduler'}->schedule('buildkeys', 0, time() ); } elsif ($command eq 'buildthesaurus') { - Echolot::Globals::get()->{'scheduler'}->schedule('buildthesaurus', time() ); + Echolot::Globals::get()->{'scheduler'}->schedule('buildthesaurus', 0, time() ); } elsif ($command eq 'delete') { Echolot::Globals::get()->{'storage'}->delete_remailer(@args); } elsif ($command eq 'setremailercaps') { 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 -# $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 (I, I) +=item B (I, I, [ I, [I]] ) Schedule execution of I for I. If I is not given it is calculated -from I and I passed to B. +from I and I passed to B. if I 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"), -- cgit v1.2.3