-
Notifications
You must be signed in to change notification settings - Fork 2
/
eventWorker.py
48 lines (42 loc) · 2.08 KB
/
eventWorker.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
40
41
42
43
44
45
46
47
48
import threading
import time
from subprocess import call
from executeAction import executeAction
class eventWorker (threading.Thread):
def __init__(self, eventKey, eventObject, dockerComposeFilename, dockerComposeProjectName, threadMap, threadFinishedMap):
threading.Thread.__init__(self)
self.eventKey = eventKey
self.eventObject = eventObject
self.dockerComposeFilename = dockerComposeFilename
self.dockerComposeProjectName = dockerComposeProjectName
self.threadMap = threadMap
self.threadFinishedMap = threadFinishedMap
def run(self):
if "dependOn" in self.eventObject:
for dependOn in self.eventObject["dependOn"]:
if not self.threadFinishedMap[dependOn]:
while not self.threadFinishedMap[dependOn]:
pass
if "seconds" in self.eventObject:
print "sleep for " + str(self.eventObject["seconds"]) + " seconds"
time.sleep(int(self.eventObject["seconds"]))
if "command" in self.eventObject:
print "execute command: " + self.eventObject["command"]
exitCode = call(self.eventObject["command"], shell=True)
if exitCode != 0:
print "command exited with exit code " + str(exitCode) + ". Abort."
return exitCode
if "commands" in self.eventObject:
for command in self.eventObject["commands"]:
print "execute command: " + command
exitCode = call(command, shell=True)
if exitCode != 0:
print "command exited with exit code " + str(exitCode) + ". Abort."
return exitCode
if "do" in self.eventObject:
doObject = self.eventObject["do"]
for action in doObject:
exitCode = executeAction(action, doObject[action], self.dockerComposeFilename, self.dockerComposeProjectName)
if exitCode != 0:
print action + " exited with exit code " + str(exitCode)
self.threadFinishedMap[self.eventKey] = True