# 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
dev-linux
Ivan Maslov 3 years ago
parent 17d2ac65ab
commit 9b94400887

@ -15,6 +15,17 @@ class Process():
- 3_STOP_SAFE_MANUAL - 3_STOP_SAFE_MANUAL
- 4_STARTED - 4_STARTED
- 5_STARTED_MANUAL - 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 mAgentHostNameStr = None
@ -77,6 +88,16 @@ class Process():
self.StatusChangeLog() self.StatusChangeLog()
return self.mStatusStr 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: 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. 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() self.StatusChangeLog()
return self.mStatusStr 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: def StopForce(self, inIsManualBool = True) -> str:
""" """
Manual/Auto stop force. Force stop don't wait process termination - it just terminate process now. Manual/Auto stop force. Force stop don't wait process termination - it just terminate process now.
@ -139,6 +170,16 @@ class Process():
self.StatusChangeLog() self.StatusChangeLog()
return self.mStatusStr 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): 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. 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) self.StopSafe(inIsManualBool=False)
return self.mStatusStr 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: def ProcessGet(inAgentHostNameStr: str, inAgentUserNameStr: str, inProcessNameWOExeStr: str) -> Process:
""" """

@ -472,7 +472,7 @@ def OrchestratorLoggerGet():
""" """
return GSettingsGet().get("Logger",None) return GSettingsGet().get("Logger",None)
def OrchestratorScheduleGet(): def OrchestratorScheduleGet() -> schedule:
""" """
Get the schedule (schedule.readthedocs.io) from the Orchestrator Get the schedule (schedule.readthedocs.io) from the Orchestrator

Loading…
Cancel
Save