-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommitterEventHandler.py
39 lines (33 loc) · 1.31 KB
/
CommitterEventHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from collections import deque
class CommitterEventHandler(object):
def __init__(self, eventQueue):
self.eventsIn = deque()
self.eventsOut = eventQueue
# used to simulate async processing
self.sleepCounter = 10
def heartbeat(self):
if self.sleepCounter != 0:
self.sleepCounter = self.sleepCounter - 1
elif len(self.eventsIn) > 0:
self.sleepCounter = 10
eventType, value = self.eventsIn.popleft()
if eventType == "JOB_SETUP":
self.handleJobSetup(value)
if eventType == "JOB_COMMIT":
self.handleJobCommit(value)
if eventType == "JOB_ABORT":
self.handleJobAbort(value)
def pushNewEvents(self, newEvents):
self.eventsIn += newEvents
def handleJobSetup(self, value):
if True:
self.eventsOut.append(("JOB_SETUP_COMPLETED", value))
else:
self.eventsOut.append(("JOB_SETUP_FAILED", value))
def handleJobCommit(self, value):
if True:
self.eventsOut.append(("JOB_COMMIT_COMPLETED", value))
else:
self.eventsOut.append(("JOB_COMMIT_FAILED", value))
def handleJobAbort(self, value):
self.eventsOut.append(("JOB_ABORT_COMPLETED", value))