summaryrefslogtreecommitdiff
path: root/Echolot/Scheduler.pm
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-06-06 10:15:53 +0000
committerPeter Palfrader <peter@palfrader.org>2003-06-06 10:15:53 +0000
commit2a9c5fec96aeb235b7fa848ecc36aee51932f756 (patch)
tree4a9fd1771ba3f953ff5309ad79c8a32dc70a89cd /Echolot/Scheduler.pm
parent5fbd0f29b9bc3664070bf624f219be2ce6c0eb31 (diff)
If we run late we should now drop actions where it does not hurt
Diffstat (limited to 'Echolot/Scheduler.pm')
-rw-r--r--Echolot/Scheduler.pm23
1 files changed, 17 insertions, 6 deletions
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 <peter@palfrader.org>
-# $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<add> (I<name>, I<interval>, I<offset>, I<what>)
+=item B<add> (I<name>, I<interval>, I<offset>, I<missok>, I<what>)
Adds a task with I<name> to the list of tasks. Every I<interval> seconds
I<what> is called. If for example I<interval> is 3600 - meaning I<what>
should be executed hourly - setting I<offset> to 600 would mean that
it get's called 10 minutes after the hour.
+I<missok> 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]";