GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 56bd3431 authored by Operator for ID30's avatar Operator for ID30

Added script and workflow error status

parent 521bb704
......@@ -53,7 +53,7 @@ class AbstractActor(object):
))
actor.trigger(inData)
def uploadDataToMongo(self, actorData={}):
def uploadDataToMongo(self, actorData={}, script=None):
if self.parent is not None:
if self.parent.mongoId is not None:
if self.actorId is None:
......@@ -61,10 +61,15 @@ class AbstractActor(object):
self.actorId = UtilsMongoDb.initActor(
workflowId=self.parent.mongoId,
name=actorPath,
actorData=actorData
actorData=actorData,
script=script
)
else:
UtilsMongoDb.addDataToActor(workflowId=self.parent.mongoId, actorId=self.actorId, actorData=actorData)
UtilsMongoDb.addDataToActor(
workflowId=self.parent.mongoId,
actorId=self.actorId,
actorData=actorData
)
def getActorPath(self):
return self.parent.getActorPath()
......@@ -23,6 +23,8 @@ __authors__ = ["O. Svensson"]
__license__ = "MIT"
__date__ = "28/05/2019"
from pypushflow import UtilsMongoDb
from pypushflow.AbstractActor import AbstractActor
......@@ -30,3 +32,7 @@ class ErrorHandler(AbstractActor):
def __init__(self, parent, name='Error handler'):
AbstractActor.__init__(self, parent=parent, name=name)
def trigger(self, inData):
UtilsMongoDb.setMongoStatus(self.parent.mongoId, 'error')
AbstractActor.trigger(self, inData=inData)
......@@ -138,6 +138,7 @@ class PythonActor(AbstractActor):
self.errorHandler = errorHandler
self.listErrorHandler = []
# Import script
self.script = script
module = importlib.import_module(os.path.splitext(script)[0])
self.actorWrapper = ActorWrapper(name, module.run)
self.inData = None
......@@ -149,7 +150,7 @@ class PythonActor(AbstractActor):
def trigger(self, inData):
self.inData = inData
self.uploadDataToMongo(actorData={'inData': inData})
self.uploadDataToMongo(actorData={'inData': inData}, script=self.script)
logger.debug('In trigger {0}, inData = {1}'.format(self.name, pprint.pformat(inData)))
if isinstance(inData, WorkflowException):
logger.error('Error from previous actor! Not running actor {0}'.format(self.name))
......@@ -158,7 +159,7 @@ class PythonActor(AbstractActor):
oldInData = workflowException.data
exceptionDict = {
'errorMessage': workflowException.errorMessage,
'traceBack': workflowException.traceBack,
'traceBack': workflowException.traceBack.split('\n'),
}
oldInData['WorkflowException'] = exceptionDict
self.triggerOnError(oldInData)
......@@ -199,7 +200,7 @@ class PythonActor(AbstractActor):
oldInData = workflowException.data
exceptionDict = {
'errorMessage': workflowException.errorMessage,
'traceBack': workflowException.traceBack,
'traceBack': workflowException.traceBack.split('\n'),
}
oldInData['WorkflowException'] = exceptionDict
self.uploadDataToMongo(actorData={
......
......@@ -60,17 +60,27 @@ def initMongo(name):
return workflowId
def setMongoStatus(workflowId, status):
mongoUrl = getMongoUrl()
if mongoUrl is not None:
collection = pymongo.MongoClient(mongoUrl).pybes.pybes
dictWorkflow = collection.find_one({'_id': workflowId})
dictWorkflow['status'] = status
collection.update_one({'_id': workflowId}, {"$set": dictWorkflow}, upsert=False)
def closeMongo(workflowId):
mongoUrl = getMongoUrl()
if mongoUrl is not None:
collection = pymongo.MongoClient(mongoUrl).pybes.pybes
dictWorkflow = collection.find_one({'_id': workflowId})
dictWorkflow['status'] = 'finished'
if dictWorkflow['status'] != 'error':
dictWorkflow['status'] = 'finished'
dictWorkflow['stopTime'] = getDateTimeString()
collection.update_one({'_id': workflowId}, {"$set": dictWorkflow}, upsert=False)
def initActor(name, workflowId, actorData={}):
def initActor(name, workflowId, actorData={}, script=None):
actorId = None
mongoUrl = getMongoUrl()
if mongoUrl is not None:
......@@ -81,6 +91,7 @@ def initActor(name, workflowId, actorData={}):
'startTime': getDateTimeString(),
'name': name,
'status': 'started',
'script': script
}
actor.update(actorData)
collection.update({'_id': workflowId}, {'$push': {'actors': actor}})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment