@ -44,6 +44,8 @@ class Process():
mAgentUserNameStr = None
mStartPathStr = None
mStartCMDStr = None
mStartArgDict = None
mStatusCheckIntervalSecFloat = None
mProcessNameWOExeStr = None
mStopSafeTimeoutSecFloat = None
mStatusStr = None # 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL
@ -76,7 +78,7 @@ class Process():
return ( self . mAgentHostNameStr . upper ( ) , self . mAgentUserNameStr . upper ( ) , self . mProcessNameWOExeStr . upper ( ) )
def __init__ ( self , inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 300 ):
def __init__ ( self , inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 300 , inStartArgDict = None , inStatusCheckIntervalSecFloat = 30 ):
"""
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
@ -92,6 +94,7 @@ class Process():
lGS = __Orchestrator__ . GSettingsGet ( )
# Check if Process is not exists in GSettings
if ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) not in lGS [ " ManagersProcessDict " ] :
self . mStartArgDict = inStartArgDict
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentUserNameStr = inAgentUserNameStr
self . mStartPathStr = inStartPathStr
@ -101,6 +104,8 @@ class Process():
lGS [ " ManagersProcessDict " ] [ ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) ] = self
lActivityDict = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = self . StatusCheck , inArgList = [ ] , inThreadBool = True )
__Orchestrator__ . ProcessorActivityItemAppend ( inActivityItemDict = lActivityDict )
if inStatusCheckIntervalSecFloat is not None : __Orchestrator__ . OrchestratorScheduleGet ( ) . every ( inStatusCheckIntervalSecFloat ) . seconds . do ( Orchestrator . OrchestratorThreadStart , self . StatusCheck )
self . mStatusCheckIntervalSecFloat = inStatusCheckIntervalSecFloat
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 :
@ -163,7 +168,7 @@ class Process():
if lLogBool == True : self . StatusChangeLog ( )
return self . mStatusStr
def Start ( self , inIsManualBool = True ) - > str :
def Start ( self , inIsManualBool = True , inStartArgDict = None ) - > str :
"""
Manual / Auto start . Manual start will block scheduling execution . To return schedule execution use def Manual2Auto .
Will not start if STOP SAFE is now and don ' t start auto is stopped manual now
@ -177,8 +182,14 @@ class Process():
__Orchestrator__ . OrchestratorLoggerGet ( ) . warning ( lStr )
return self . mStatusStr
# Send activity item to agent - wait result
if self . mStartPathStr is not None : lCMDStr = f " start { os . path . abspath ( self . mStartPathStr ) } "
elif self . mStartCMDStr is not None : lCMDStr = f " start { self . mStartCMDStr } "
if self . mStartPathStr is not None : lCMDStr = os . path . abspath ( self . mStartPathStr )
elif self . mStartCMDStr is not None : lCMDStr = self . mStartCMDStr
# Append args
if inStartArgDict is not None : self . mStartArgDict = inStartArgDict
if self . mStartArgDict is not None :
for lItemKeyStr in self . mStartArgDict :
lItemValueStr = self . mStartArgDict [ lItemKeyStr ]
lCMDStr = f " { lCMDStr } { lItemKeyStr } { lItemValueStr } "
#import pdb
#pdb.set_trace()
self . MuteWait ( )
@ -340,6 +351,14 @@ class Process():
if lWarnSafeBool == True : __Orchestrator__ . OrchestratorLoggerGet ( ) . warning ( f " Managers.Process ( { self . mAgentHostNameStr } , { self . mAgentUserNameStr } , { self . mProcessNameWOExeStr } ): Safe status has been catched when safe > change saved status to stopped. " )
return self . mStatusStr
def StatusCheckIntervalRestore ( self ) :
""" Call from orchestrator when init
"""
if self . mStatusCheckIntervalSecFloat is not None :
__Orchestrator__ . OrchestratorLoggerGet ( ) . info ( f " Managers.Process ( { self . mAgentHostNameStr } , { self . mAgentUserNameStr } , { self . mProcessNameWOExeStr } ): Restore schedule to StatusCheck in interval of { self . mStatusCheckIntervalSecFloat } sec. " )
__Orchestrator__ . OrchestratorScheduleGet ( ) . every ( self . mStatusCheckIntervalSecFloat ) . seconds . do ( Orchestrator . OrchestratorThreadStart , self . StatusCheck )
def StatusRestore ( self ) :
"""
Execute the StatusCheck , after that restore status to the saved state ( see StatusSave ) . Work when orchestrator is restarted .
@ -349,14 +368,15 @@ class Process():
self . StatusCheck ( ) # check current status
# Do some action
if self . mStatusSavedStr != self . mStatusStr and self . mStatusSavedStr is not None :
lManualBool = False
if " MANUAL " in self . mStatusSavedStr :
lManualBool = True
#lManualBool = False
#if "MANUAL" in self.mStatusSavedStr :
# lManualBool = True
if " STOPPED " in self . mStatusSavedStr and " STOPPED " not in self . mStatusStr :
self . StopSafe ( inIsManualBool = lManualBool )
self . StopSafe ( inIsManualBool = True )
if " STARTED " in self . mStatusSavedStr and " STARTED " not in self . mStatusStr :
self . Start ( inIsManualBool = lManualBool )
self . Start ( inIsManualBool = True )
Orchestrator . OrchestratorLoggerGet ( ) . info ( f " Managers.Process ( { self . mAgentHostNameStr } , { self . mAgentUserNameStr } , { self . mProcessNameWOExeStr } ): Status has been restored to { self . mStatusSavedStr } " )
self . mStatusStr = self . mStatusSavedStr
self . mStatusSavedStr = None
return self . mStatusStr