@ -8,6 +8,9 @@ class Process():
With Process instance you can automate your process activity . Use schedule package to set interval when process should be active and when not .
With Process instance you can automate your process activity . Use schedule package to set interval when process should be active and when not .
All defs in class are pickle safe ! After orchestrator restart ( if not the force stop of the orchestrator process ) your instance with properties will be restored . But it not coverage the scheduler which is in __Orchestrator__ .
After orc restart you need to reinit all schedule rules : Orchestrator . OrchestratorScheduleGet
Process instance has the following statuses :
Process instance has the following statuses :
- 0 _STOPPED
- 0 _STOPPED
- 1 _STOPPED_MANUAL
- 1 _STOPPED_MANUAL
@ -17,7 +20,8 @@ class Process():
- 5 _STARTED_MANUAL
- 5 _STARTED_MANUAL
. . code - block : : python
. . code - block : : python
lProcess = Orchestrator . Managers . Process ( inAgentHostNameStr = " PCNAME " , inAgentUserNameStr = " USER " ,
# For the safe init class use ProcessInitSafe
lProcess = Orchestrator . Managers . ProcessInitSafe ( inAgentHostNameStr = " PCNAME " , inAgentUserNameStr = " USER " ,
inProcessNameWOExeStr = " notepad " , inStartCMDStr = " notepad " , inStopSafeTimeoutSecFloat = 3 )
inProcessNameWOExeStr = " notepad " , inStartCMDStr = " notepad " , inStopSafeTimeoutSecFloat = 3 )
# Async way to run job
# Async way to run job
lProcess . ScheduleStatusCheckEverySeconds ( inIntervalSecondsInt = 5 )
lProcess . ScheduleStatusCheckEverySeconds ( inIntervalSecondsInt = 5 )
@ -62,16 +66,32 @@ class Process():
time . sleep ( lIntervalSecFloat )
time . sleep ( lIntervalSecFloat )
return None
return None
def __init__ ( self , inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 120 ) :
def __init__ ( self , inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 300 ) :
"""
Init the class instance .
! ATTENTION ! Function can raise exception if process with the same ( inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr ) is already exists in GSettings ( can be restored from previous Orchestrator session ) . See ProcessInitSafe to sefaty init the instance or restore previous
! ATTENTION ! Schedule options you must
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: param inStartPathStr : Path to start process ( . cmd / . exe or something else ) . Path can be relative ( from orc working directory ) or absolute
: param inStartCMDStr : CMD script to start program ( if no start file is exists )
: param inStopSafeTimeoutSecFloat : Time to wait for stop safe . After that do the stop force ( if process is not stopped )
"""
lGS = __Orchestrator__ . GSettingsGet ( )
# Check if Process is not exists in GSettings
if ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) not in lGS [ " ManagersProcessDict " ] :
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentUserNameStr = inAgentUserNameStr
self . mAgentUserNameStr = inAgentUserNameStr
self . mStartPathStr = inStartPathStr
self . mStartPathStr = inStartPathStr
self . mStartCMDStr = inStartCMDStr
self . mStartCMDStr = inStartCMDStr
self . mProcessNameWOExeStr = inProcessNameWOExeStr
self . mProcessNameWOExeStr = inProcessNameWOExeStr
self . mStopSafeTimeoutSecFloat = inStopSafeTimeoutSecFloat
self . mStopSafeTimeoutSecFloat = inStopSafeTimeoutSecFloat
__Orchestrator__ . GSettingsGet ( ) [ " ManagersProcessDict " ] [ ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) ] = self
lGS [ " ManagersProcessDict " ] [ ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) ] = self
lActivityDict = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = self . StatusCheck , inArgList = [ ] )
lActivityDict = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = self . StatusCheck , inArgList = [ ] )
__Orchestrator__ . ProcessorActivityItemAppend ( inActivityItemDict = lActivityDict )
__Orchestrator__ . ProcessorActivityItemAppend ( inActivityItemDict = lActivityDict )
else : raise Exception ( f " Managers.Process ( { inAgentHostNameStr } , { inAgentUserNameStr } , { inProcessNameWOExeStr } ): Can ' t init the Process instance because it already inited in early (see ProcessInitSafe) " )
def ManualStopTriggerSet ( self , inMSTdTSecFloat : float , inMSTdNInt : int ) - > None :
def ManualStopTriggerSet ( self , inMSTdTSecFloat : float , inMSTdNInt : int ) - > None :
"""
"""
@ -399,15 +419,36 @@ class Process():
self . StopSafe ( inIsManualBool = False )
self . StopSafe ( inIsManualBool = False )
return self . mStatusStr
return self . mStatusStr
def ScheduleStatusCheckEverySeconds ( self , inIntervalSecondsInt = 120 ) :
def ProcessInitSafe ( inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 300 ) :
"""
"""
Run status check every interval in second you specify .
Exception safe function . Check if process instance is not exists in GSettings ( it can be after restart because Orchestrator restore objects from dump of the previous Orchestrator session )
Return existing instance ( if exists ) or create new instance and return it .
: param inIntervalSecondsInt : Interval in seconds . Default is 120
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: return : None
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: param inStartPathStr : Path to start process ( . cmd / . exe or something else ) . Path can be relative ( from orc working directory ) or absolute
: param inStartCMDStr : CMD script to start program ( if no start file is exists )
: param inStopSafeTimeoutSecFloat : Time to wait for stop safe . After that do the stop force ( if process is not stopped )
: return : Process instance
"""
"""
# Check job in threaded way
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr , inProcessNameWOExeStr = inProcessNameWOExeStr )
__Orchestrator__ . OrchestratorScheduleGet ( ) . every ( inIntervalSecondsInt ) . seconds . do ( __Orchestrator__ . OrchestratorThreadStart , self . StatusCheck )
if lProcess is not None : return lProcess . mStatusStr
else : return Process ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr , inProcessNameWOExeStr = inProcessNameWOExeStr ,
inStartPathStr = inStartPathStr , inStartCMDStr = inStartCMDStr , inStopSafeTimeoutSecFloat = inStopSafeTimeoutSecFloat )
def ProcessExists ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str ) - > bool :
"""
Check if the Process instance is exists in GSettings by the ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str )
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: return : True - process exists in gsettings ; False - else
"""
return ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) in __Orchestrator__ . GSettingsGet ( ) [ " ManagersProcessDict " ]
def ProcessGet ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str ) - > Process :
def ProcessGet ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str ) - > Process :
"""
"""
@ -603,3 +644,18 @@ def ProcessManualStopListClear(inAgentHostNameStr: str, inAgentUserNameStr: str,
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
inProcessNameWOExeStr = inProcessNameWOExeStr )
inProcessNameWOExeStr = inProcessNameWOExeStr )
if lProcess is not None : lProcess . ManualStopListClear ( )
if lProcess is not None : lProcess . ManualStopListClear ( )
def ProcessScheduleStatusCheckEverySeconds ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str , inIntervalSecondsInt : int = 120 ) :
"""
Run status check every interval in second you specify .
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: param inIntervalSecondsInt : Interval in seconds . Default is 120
: return : None
"""
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
inProcessNameWOExeStr = inProcessNameWOExeStr )
# Check job in threaded way
__Orchestrator__ . OrchestratorScheduleGet ( ) . every ( inIntervalSecondsInt ) . seconds . do ( __Orchestrator__ . OrchestratorThreadStart , lProcess . StatusCheck )