summaryrefslogtreecommitdiffstats
path: root/whine.pl
diff options
context:
space:
mode:
authorbugreport%peshkin.net <>2004-08-17 23:51:04 +0200
committerbugreport%peshkin.net <>2004-08-17 23:51:04 +0200
commit2f9f28d0bfb1f321d1548844a41aaf2d51789695 (patch)
tree35c00705bfae1d74f85cf11f1185f52299bee222 /whine.pl
parent9e6914114a17d5b1ca92ae4aa1f9796d1ba66df8 (diff)
downloadbugzilla-2f9f28d0bfb1f321d1548844a41aaf2d51789695.tar.gz
bugzilla-2f9f28d0bfb1f321d1548844a41aaf2d51789695.tar.xz
Bug 255772: Prevent whine.pl from running endless whining loop
patch by erik r=joel, jouni a=myk
Diffstat (limited to 'whine.pl')
-rwxr-xr-xwhine.pl39
1 files changed, 30 insertions, 9 deletions
diff --git a/whine.pl b/whine.pl
index 38cd84894..dc3f2302c 100755
--- a/whine.pl
+++ b/whine.pl
@@ -39,6 +39,12 @@ my $template = Bugzilla->template;
my $dbh = Bugzilla->dbh;
my $sth;
+# @seen_schedules is a list of all of the schedules that have already been
+# touched by reset_timer. If reset_timer sees a schedule more than once, it
+# sets it to NULL so it won't come up again until the next execution of
+# whine.pl
+my @seen_schedules = ();
+
# These statement handles should live outside of their functions in order to
# allow the database to keep their SQL compiled.
my $sth_run_queries =
@@ -517,6 +523,15 @@ sub check_today {
sub reset_timer {
my $schedule_id = shift;
+ # Schedules may not be executed more than once for each invocation of
+ # whine.pl -- there are legitimate circumstances that can cause this, like
+ # a set of whines that take a very long time to execute, so it's done
+ # quietly.
+ if (grep(/^$schedule_id$/, @seen_schedules)) {
+ null_schedule($schedule_id);
+ }
+ push @seen_schedules, $schedule_id;
+
$sth = $dbh->prepare( "SELECT run_day, run_time FROM whine_schedules " .
"WHERE id=?" );
$sth->execute($schedule_id);
@@ -571,17 +586,23 @@ sub reset_timer {
$sth->execute($minute_offset, $schedule_id);
} else {
# The minute offset is zero or less, which is not supposed to happen.
- # This is a kind of safeguard against infinite loops. NULL schedules
- # will not be available to get_next_event until they are rescheduled.
- $sth = $dbh->prepare("UPDATE whine_schedules " .
- "SET run_next = NULL " .
- "WHERE id=?");
- $sth->execute($schedule_id);
- # complain to STDERR
- print STDERR "Bad minute_offset for schedule ID $schedule_id\n";
+ # complain to STDERR
+ null_schedule($schedule_id);
+ print STDERR "Error: bad minute_offset for schedule ID $schedule_id\n";
}
}
+# null_schedule is used to safeguard against infinite loops. Schedules with
+# run_next set to NULL will not be available to get_next_event until they are
+# rescheduled, which only happens when whine.pl starts.
+sub null_schedule {
+ my $schedule_id = shift;
+ $sth = $dbh->prepare("UPDATE whine_schedules " .
+ "SET run_next = NULL " .
+ "WHERE id=?");
+ $sth->execute($schedule_id);
+}
+
# get_next_date determines the difference in days between now and the next
# time a schedule should run, excluding today
#
@@ -628,7 +649,7 @@ sub get_next_date {
}
$add_days = $day_num - $now_weekday;
- if ($add_days < 0) { # it's next week
+ if ($add_days <= 0) { # it's next week
$add_days += 7;
}
}