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

Commit 147c2943 authored by Operator for ID30's avatar Operator for ID30

Improved logging and implemented Request Status

parent a1bcd4a7
......@@ -23,10 +23,17 @@ __authors__ = ["O. Svensson"]
__license__ = "MIT"
__date__ = "28/05/2019"
from pypushflow.AbstractActor import AbstractActor
from pypushflow import UtilsMongoDb
from pypushflow.AbstractActor import AbstractActor
class RequestStatus(AbstractActor):
def __init__(self, parent, name='Request status'):
def __init__(self, parent, name='Request status', status=None):
AbstractActor.__init__(self, parent=parent, name=name)
self.status=status
def trigger(self, inData):
if self.parent is not None and hasattr(self.parent, 'mongoId') and self.status is not None:
UtilsMongoDb.setMongoStatus(self.parent.mongoId, self.status)
AbstractActor.trigger(self, inData=inData)
......@@ -41,7 +41,7 @@ class Workflow(object):
self.listOnErrorActor = []
self.mongoId = UtilsMongoDb.initMongo(name=name)
self.listActorRef = []
self.logger = self.initLogger()
self.logger = self.initLogger(name)
def connectOnError(self, actor):
self.logger.debug("In Workflow '{0}' connectOnError, actor name {1}".format(self.name, actor.name))
......@@ -64,15 +64,18 @@ class Workflow(object):
def getListActorRef(self):
return self.listActorRef
def initLogger(self):
logger = logging.getLogger('pypushflow')
def initLogger(self, name):
user = os.environ.get("USER", "unknown")
initiator = os.environ.get("PYPUSHFLOW_INITIATOR", "pypushflow")
log_file_dir = pathlib.Path("/tmp/{0}/{1}".format(user, initiator))
if not log_file_dir.exists():
log_file_dir.mkdir(mode=0o755, parents=True)
log_file_path = log_file_dir / "pypushfloww.log"
maxBytes = 1e6
log_file_path = log_file_dir / "{0}.log".format(name)
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('pypushflow')
# with open(log_file_path, "w") as fd:
# fd.write("Test line\n")
maxBytes = 1e7
backupCount = 10
fileHandler = logging.handlers.RotatingFileHandler(
log_file_path, maxBytes=maxBytes, backupCount=backupCount)
......@@ -81,5 +84,8 @@ class Workflow(object):
fileHandler.setFormatter(formatter)
fileHandler.setLevel(logging.DEBUG)
logger.addHandler(fileHandler)
logger.info("Logging started")
logger.info("")
logger.info("")
logger.info("Starting new workflow " + name)
logger.info("")
return logger
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