Skip to content

Commit edb034b

Browse files
committed
Fixed _snooze method to properly handle filecnt and maintain original behavior
1 parent 8093aa2 commit edb034b

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

Mailman/Queue/Runner.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,31 @@ def _doperiodic(self):
420420
"""
421421
pass
422422

423-
def _snooze(self, secs):
424-
"""Sleep for the specified number of seconds, but wake up if the
425-
stop flag is set.
426-
423+
def _snooze(self, filecnt):
424+
"""Sleep for a while, but check for stop flag periodically.
425+
426+
Implements exponential backoff when no files are found to process.
427+
427428
Args:
428-
secs: Number of seconds to sleep.
429+
filecnt: Number of files processed in the last iteration
429430
"""
430-
endtime = time.time() + secs
431+
if filecnt > 0:
432+
# Reset backoff when files are found
433+
self._current_backoff = self.INITIAL_BACKOFF
434+
# Only log if we're sleeping for more than 5 seconds
435+
if self.SLEEPTIME > 5:
436+
syslog('debug', '%s: Sleeping for %d seconds after processing %d files in this iteration',
437+
self.__class__.__name__, self.SLEEPTIME, filecnt)
438+
sleep_time = self.SLEEPTIME
439+
else:
440+
# No files found, use exponential backoff
441+
sleep_time = min(self._current_backoff, self.MAX_BACKOFF)
442+
syslog('debug', '%s: No files to process, sleeping for %d seconds',
443+
self.__class__.__name__, sleep_time)
444+
# Double the backoff time for next iteration, up to MAX_BACKOFF
445+
self._current_backoff = min(self._current_backoff * 2, self.MAX_BACKOFF)
446+
447+
endtime = time.time() + sleep_time
431448
while time.time() < endtime and not self._stop:
432449
time.sleep(0.1)
433450

0 commit comments

Comments
 (0)