From 2a9c5fec96aeb235b7fa848ecc36aee51932f756 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 6 Jun 2003 10:15:53 +0000 Subject: If we run late we should now drop actions where it does not hurt --- Echolot/Scheduler.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'Echolot') diff --git a/Echolot/Scheduler.pm b/Echolot/Scheduler.pm index 39c785f..d2e8d92 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.14 2003/01/14 05:25:35 weasel Exp $ +# $Id: Scheduler.pm,v 1.15 2003/06/06 10:15:02 weasel Exp $ # =pod @@ -37,16 +37,19 @@ sub new { return $self; }; -=item B (I, I, I, I) +=item B (I, I, I, I, I) Adds a task with I to the list of tasks. Every I seconds I is called. If for example I is 3600 - meaning I should be executed hourly - setting I to 600 would mean that it get's called 10 minutes after the hour. +I indicates that it is ok to miss one run of this job. This can happen +if we run behind schedule for instance. + =cut -sub add($$$$$) { - my ($self, $name, $interval, $offset, $what) = @_; +sub add($$$$$$) { + my ($self, $name, $interval, $offset, $missok, $what) = @_; Echolot::Log::logdie("Must not add zero intervall for job $name.") unless $interval; @@ -60,7 +63,8 @@ sub add($$$$$) { interval => $interval, offset => $offset, what => $what, - order => $ORDER++ + order => $ORDER++, + missok => $missok, }; $self->schedule($name, 1); @@ -93,6 +97,12 @@ sub schedule($$$;$$) { my $now = time(); $for = $now - $now % $interval + $offset; ($for <= $now) and $for += $interval; + my $cnt = 0; + while ($self->{'tasks'}->{$name}->{'missok'} && ($for <= $now)) { + $for += $interval; + $cnt ++; + }; + Echolot::Log::debug("Skipping n runs of $name.") if $cnt; }; $arguments = [] unless defined $arguments; @@ -130,7 +140,8 @@ sub run($) { my $now = time(); my $task = $self->{'schedule'}->[0]; if ($task->{'start'} < $now) { - Echolot::Log::warn("Task $task->{'name'} could not be started on time."); + Echolot::Log::warn("Task $task->{'name'} could not be started on time.") + unless ($task->{'start'} == 0); } else { Echolot::Log::debug("zZzZZzz."); $PROGRAM_NAME = "pingd [sleeping]"; -- cgit v1.2.3