mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-02 20:59:06 +08:00
Merge #1671 Avoid deep recursion when handling a large queue of events
This commit is contained in:
@@ -15,6 +15,7 @@ however Brew sends to topic brew.build.complete, etc.
|
||||
from __future__ import absolute_import
|
||||
from functools import wraps
|
||||
import sched
|
||||
import threading
|
||||
import time
|
||||
|
||||
from module_build_service.common import log
|
||||
@@ -40,6 +41,10 @@ class Scheduler(sched.scheduler):
|
||||
are executed.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
sched.scheduler.__init__(self, *args, **kwargs)
|
||||
self.local = threading.local()
|
||||
|
||||
def add(self, handler, arguments=()):
|
||||
"""
|
||||
Schedule execution of `handler` with `arguments`.
|
||||
@@ -50,10 +55,20 @@ class Scheduler(sched.scheduler):
|
||||
"""
|
||||
Runs scheduled handlers.
|
||||
"""
|
||||
log.debug("Running event scheduler with following events:")
|
||||
for event in self.queue:
|
||||
log.debug(" %r", event)
|
||||
sched.scheduler.run(self)
|
||||
if getattr(self.local, 'running', False):
|
||||
return
|
||||
|
||||
try:
|
||||
self.local.running = True
|
||||
# Note that events that are added during the execution of the
|
||||
# handlers are executed as part of the .run() call without
|
||||
# further logging.
|
||||
log.debug("Running event scheduler with following events:")
|
||||
for event in self.queue:
|
||||
log.debug(" %r", event)
|
||||
sched.scheduler.run(self)
|
||||
finally:
|
||||
self.local.running = False
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user