Merge "Copy Gerrit delay to GitHub driver" into feature/zuulv3
This commit is contained in:
@@ -135,6 +135,7 @@ class GithubEventConnector(threading.Thread):
|
||||
"""Move events from GitHub into the scheduler"""
|
||||
|
||||
log = logging.getLogger("zuul.GithubEventConnector")
|
||||
delay = 3.0
|
||||
|
||||
def __init__(self, connection):
|
||||
super(GithubEventConnector, self).__init__()
|
||||
@@ -147,9 +148,17 @@ class GithubEventConnector(threading.Thread):
|
||||
self.connection.addEvent(None)
|
||||
|
||||
def _handleEvent(self):
|
||||
json_body, event_type = self.connection.getEvent()
|
||||
ts, json_body, event_type = self.connection.getEvent()
|
||||
if self._stopped:
|
||||
return
|
||||
# Github can produce inconsistent data immediately after an
|
||||
# event, So ensure that we do not deliver the event to Zuul
|
||||
# until at least a certain amount of time has passed. Note
|
||||
# that if we receive several events in succession, we will
|
||||
# only need to delay for the first event. In essence, Zuul
|
||||
# should always be a constant number of seconds behind Github.
|
||||
now = time.time()
|
||||
time.sleep(max((ts + self.delay) - now, 0.0))
|
||||
|
||||
# If there's any installation mapping information in the body then
|
||||
# update the project mapping before any requests are made.
|
||||
@@ -543,7 +552,7 @@ class GithubConnection(BaseConnection):
|
||||
return token
|
||||
|
||||
def addEvent(self, data, event=None):
|
||||
return self.event_queue.put((data, event))
|
||||
return self.event_queue.put((time.time(), data, event))
|
||||
|
||||
def getEvent(self):
|
||||
return self.event_queue.get()
|
||||
|
||||
Reference in New Issue
Block a user