From 9b944008875dc3388df8ec79cb88de853aba56b7 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Mon, 17 Jan 2022 08:35:05 +0300 Subject: [PATCH] # Orchestrator.Managers.Process: add def to the consolidated check status and then check status in Process instance (StartCheck, StopSafeCheck, StopForceCheck) # next todo: form of schedule - has until but not has 'from' # next todo: create def to check safe signal termination --- .../Orchestrator/Managers/Process.py | 50 +++++++++++++++++++ .../Orchestrator/__Orchestrator__.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Sources/pyOpenRPA/Orchestrator/Managers/Process.py b/Sources/pyOpenRPA/Orchestrator/Managers/Process.py index 46078fc6..31b98a9f 100644 --- a/Sources/pyOpenRPA/Orchestrator/Managers/Process.py +++ b/Sources/pyOpenRPA/Orchestrator/Managers/Process.py @@ -15,6 +15,17 @@ class Process(): - 3_STOP_SAFE_MANUAL - 4_STARTED - 5_STARTED_MANUAL + + + .. code-block:: python + lProcess = Orchestrator.Managers.Process(inAgentHostNameStr="PCNAME",inAgentUserNameStr="USER", + inProcessNameWOExeStr="notepad",inStartCMDStr="notepad",inStopSafeTimeoutSecFloat=3) + # Async way to run job + lProcess.ScheduleStatusCheckEverySeconds(inIntervalSecondsInt=5) + Orchestrator.OrchestratorScheduleGet().every(5).seconds.do(Orchestrator.OrchestratorThreadStart, + lProcess.StartCheck) + # OR (sync mode) + Orchestrator.OrchestratorScheduleGet().every(5).seconds.do(lProcess.StartCheck) """ mAgentHostNameStr = None @@ -77,6 +88,16 @@ class Process(): self.StatusChangeLog() return self.mStatusStr + def StartCheck(self) -> str: + """ + Start program if auto stopped (0_STOPPED). + + :return: Process status. See self.mStatusStr. 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL + """ + if self.mStatusStr == "0_STOPPED": + self.Start(inIsManualBool=False) + return self.mStatusStr + def StopSafe(self, inIsManualBool = True) -> str: """ Manual/Auto stop safe. Stop safe is the operation which send signal to process to terminate own work (send term signal to process). Managers.Process wait for the mStopSafeTimeoutSecFloat seconds. After that, if process is not terminated - self will StopForce it. @@ -115,6 +136,16 @@ class Process(): self.StatusChangeLog() return self.mStatusStr + def StopSafeCheck(self) -> str: + """ + Stop safe program if auto started (4_STARTED). + + :return: Process status. See self.mStatusStr. 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL + """ + if self.mStatusStr == "4_STARTED": + self.StopSafe(inIsManualBool=False) + return self.mStatusStr + def StopForce(self, inIsManualBool = True) -> str: """ Manual/Auto stop force. Force stop don't wait process termination - it just terminate process now. @@ -139,6 +170,16 @@ class Process(): self.StatusChangeLog() return self.mStatusStr + def StopForceCheck(self) -> str: + """ + Stop force program if auto started (4_STARTED). + + :return: Process status. See self.mStatusStr. 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL + """ + if self.mStatusStr == "4_STARTED": + self.StopForce(inIsManualBool=False) + return self.mStatusStr + def RestartSafe(self, inIsManualBool = True): """ Manual/Auto restart safe. Restart safe is the operation which send signal to process to terminate own work (send term signal to process). Then it run process. Managers.Process wait for the mStopSafeTimeoutSecFloat seconds. After that, if process is not terminated - self will StopForce it. @@ -228,6 +269,15 @@ class Process(): self.StopSafe(inIsManualBool=False) return self.mStatusStr + def ScheduleStatusCheckEverySeconds(self,inIntervalSecondsInt=120): + """ + Run status check every interval in second you specify. + + :param inIntervalSecondsInt: Interval in seconds. Default is 120 + :return: None + """ + # Check job in threaded way + __Orchestrator__.OrchestratorScheduleGet().every(inIntervalSecondsInt).seconds.do(__Orchestrator__.OrchestratorThreadStart,self.StatusCheck) def ProcessGet(inAgentHostNameStr: str, inAgentUserNameStr: str, inProcessNameWOExeStr: str) -> Process: """ diff --git a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py index e750e850..5c027cc3 100644 --- a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py +++ b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py @@ -472,7 +472,7 @@ def OrchestratorLoggerGet(): """ return GSettingsGet().get("Logger",None) -def OrchestratorScheduleGet(): +def OrchestratorScheduleGet() -> schedule: """ Get the schedule (schedule.readthedocs.io) from the Orchestrator