Newer
Older
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import threading
import time
from dm.common.utility.loggingManager import LoggingManager
from dm.common.utility.dmSubprocess import DmSubprocess
class ExecutionThread(threading.Thread):
THREAD_EVENT_TIMEOUT_IN_SECONDS = 10.0
def __init__ (self, name, executionManager, executionQueue):
threading.Thread.__init__(self)
self.setName(name)
self.exitFlag = False
self.executionManager = executionManager
self.executionQueue = executionQueue
self.logger = LoggingManager.getInstance().getLogger(name)
def processFile(self, fileInfo):
try:
pass
except Exception, ex:
self.logger.exception(ex)
def run(self):
self.logger.debug('Starting thread: %s' % self.getName())
while True:
self.executionManager.clearEvent()
if self.exitFlag:
self.logger.debug('Exit flag is set')
break
while True:
try:
queuedTuple = self.executionQueue.pop()
if queuedTuple is None:
break
processingJob, childProcess = queuedTuple
self.logger.debug('Execution queue depth after pop: %s' % self.executionQueue.getLength())
self.logger.debug('Starting child process: %s' % childProcess)
command = childProcess.get('command')
workingDir = childProcess.get('workingDir')
processingJob.childProcessStarted(childProcess)
p = DmSubprocess.executeCommandAndIgnoreFailure(command, workingDir)
processInfo = p.toDict()
if p.getExitStatus() == 0:
processingJob.childProcessCompleted(childProcess, processInfo)
else:
processingJob.childProcessFailed(childProcess, processInfo)
except Exception, ex:
self.logger.exception(ex)
processingJob.childProcessFailed(childProcess, errorMessage=str(ex))
self.executionManager.waitOnEvent(self.THREAD_EVENT_TIMEOUT_IN_SECONDS)
self.logger.debug('%s is done' % self.getName())
def stop(self):
self.exitFlag = True
####################################################################
# Testing
if __name__ == '__main__':
pass