diff options
author | bugreport%peshkin.net <> | 2004-08-17 21:51:04 +0000 |
---|---|---|
committer | bugreport%peshkin.net <> | 2004-08-17 21:51:04 +0000 |
commit | 2f9f28d0bfb1f321d1548844a41aaf2d51789695 (patch) | |
tree | 35c00705bfae1d74f85cf11f1185f52299bee222 /whine.pl | |
parent | Bug 244239: Add group-based pronouns to query (diff) | |
download | bugzilla-2f9f28d0bfb1f321d1548844a41aaf2d51789695.tar.gz bugzilla-2f9f28d0bfb1f321d1548844a41aaf2d51789695.tar.bz2 bugzilla-2f9f28d0bfb1f321d1548844a41aaf2d51789695.zip |
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-x | whine.pl | 39 |
1 files changed, 30 insertions, 9 deletions
@@ -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; } } |