From 8cffeb627e0f58fde77df821bebaa5107c5eb5ea Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Tue, 4 Jan 2022 18:22:21 +0300 Subject: [PATCH] # Managers.Process write code (start stop force and check) --- .../Orchestrator/Managers/Process.py | 50 ++++++++++++++++--- .../Orchestrator/Managers/__init__.py | 3 +- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Sources/pyOpenRPA/Orchestrator/Managers/Process.py b/Sources/pyOpenRPA/Orchestrator/Managers/Process.py index e2fca829..fc6a1db7 100644 --- a/Sources/pyOpenRPA/Orchestrator/Managers/Process.py +++ b/Sources/pyOpenRPA/Orchestrator/Managers/Process.py @@ -1,6 +1,6 @@ - - +from .. import __Orchestrator__ +import os class Process(): """ @@ -24,7 +24,7 @@ class Process(): mStopSafeTimeoutSecFloat = None mStatusStr = None # 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL - def __init__(self, inAgentHostNameStr, inAgentUserNameStr): + def __init__(self, inAgentHostNameStr, inAgentUserNameStr, mStartPathStr, mProcessNameWOExeStr, mStopSafeTimeoutSecFloat=120): self.mAgentHostNameStr = inAgentHostNameStr self.mAgentUserNameStr = inAgentUserNameStr @@ -46,7 +46,22 @@ class Process(): :param inIsManualBool: Default is True - Mark this operation as manual - StatusCheckStart/Stop will be blocked - only StatusCheck will be working. False - Auto operation :return: """ - pass + # Send activity item to agent - wait result + lCMDStr = f"start {os.path.abspath(self.mStartPathStr)}" + lActivityItemStart = __Orchestrator__.ProcessorActivityItemCreate(inDef="OSCMD", + inArgDict={"inCMDStr":lCMDStr,"inSendOutputToOrchestratorLogsBool":False}, + inArgGSettingsStr="inGSettings") + lGUIDStr = __Orchestrator__.AgentActivityItemAdd(inHostNameStr=self.mAgentHostNameStr, + inUserStr=self.mAgentUserNameStr, + inActivityItemDict=lActivityItemStart) + lStartResult = __Orchestrator__.AgentActivityItemReturnGet(inGUIDStr=lGUIDStr) + if inIsManualBool==True: + self.mStatusStr = "5_STARTED_MANUAL" + else: + self.mStatusStr = "4_STARTED" + # Log info about process + lL = __Orchestrator__.OrchestratorLoggerGet() + lL.info(f"Managers.Process: {self.mProcessNameWOExeStr} change status to {self.mStatusStr})") def StopSafe(self, inIsManualBool = True): """ @@ -66,7 +81,21 @@ class Process(): :param inIsManualBool: Default is True - Mark this operation as manual - StatusCheckStart/Stop will be blocked - only StatusCheck will be working. False - Auto operation :return: """ - pass + # Send activity item to agent - wait result + lCMDStr = f'taskkill /im "{self.mProcessNameWOExeStr}" /fi "username eq %USERNAME%"' + lActivityItemStart = __Orchestrator__.ProcessorActivityItemCreate( + inDef="OSCMD",inArgDict={"inCMDStr": lCMDStr,"inSendOutputToOrchestratorLogsBool":False},inArgGSettingsStr="inGSettings") + lGUIDStr = __Orchestrator__.AgentActivityItemAdd(inHostNameStr=self.mAgentHostNameStr, + inUserStr=self.mAgentUserNameStr, + inActivityItemDict=lActivityItemStart) + lStartResult = __Orchestrator__.AgentActivityItemReturnGet(inGUIDStr=lGUIDStr) + if inIsManualBool==True: + self.mStatusStr = "1_STOPPED_MANUAL" + else: + self.mStatusStr = "0_STOPPED" + # Log info about process + lL = __Orchestrator__.OrchestratorLoggerGet() + lL.info(f"Managers.Process: {self.mProcessNameWOExeStr} change status to {self.mStatusStr})") def RestartSafe(self, inIsManualBool = True): @@ -95,7 +124,16 @@ class Process(): :return: """ - pass + # Send activity item to agent - wait result + lActivityItemUserProcessList = __Orchestrator__.ProcessorActivityItemCreate(inDef="ProcessWOExeUpperUserListGet") + lGUIDStr = __Orchestrator__.AgentActivityItemAdd(inHostNameStr=self.mAgentHostNameStr,inUserStr=self.mAgentUserNameStr,inActivityItemDict=lActivityItemUserProcessList) + lUserProcessList = __Orchestrator__.AgentActivityItemReturnGet(inGUIDStr=lGUIDStr) + if self.mProcessNameWOExeStr.upper() in lUserProcessList: + if self.mStatusStr == "1_STOPPED_MANUAL": self.mStatusStr = "5_STARTED_MANUAL" + if self.mStatusStr == "0_STOPPED": self.mStatusStr = "4_STARTED" + else: + if self.mStatusStr == "5_STARTED_MANUAL": self.mStatusStr = "1_STOPPED_MANUAL" + if self.mStatusStr == "4_STARTED": self.mStatusStr = "0_STOPPED" def StatusCheckStart(self): """ diff --git a/Sources/pyOpenRPA/Orchestrator/Managers/__init__.py b/Sources/pyOpenRPA/Orchestrator/Managers/__init__.py index e449f4e5..03aac9d7 100644 --- a/Sources/pyOpenRPA/Orchestrator/Managers/__init__.py +++ b/Sources/pyOpenRPA/Orchestrator/Managers/__init__.py @@ -1 +1,2 @@ -from .ControlPanel import ControlPanel \ No newline at end of file +from .ControlPanel import ControlPanel +from .Process import Process \ No newline at end of file