@ -44,6 +44,8 @@ class Process():
mAgentUserNameStr = None
mAgentUserNameStr = None
mStartPathStr = None
mStartPathStr = None
mStartCMDStr = None
mStartCMDStr = None
mStartArgDict = None
mStatusCheckIntervalSecFloat = None
mProcessNameWOExeStr = None
mProcessNameWOExeStr = None
mStopSafeTimeoutSecFloat = None
mStopSafeTimeoutSecFloat = None
mStatusStr = None # 0_STOPPED 1_STOPPED_MANUAL 2_STOP_SAFE 3_STOP_SAFE_MANUAL 4_STARTED 5_STARTED_MANUAL
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 ( ) )
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 .
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 ! 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 ( )
lGS = __Orchestrator__ . GSettingsGet ( )
# Check if Process is not exists in GSettings
# Check if Process is not exists in GSettings
if ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) not in lGS [ " ManagersProcessDict " ] :
if ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) not in lGS [ " ManagersProcessDict " ] :
self . mStartArgDict = inStartArgDict
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentUserNameStr = inAgentUserNameStr
self . mAgentUserNameStr = inAgentUserNameStr
self . mStartPathStr = inStartPathStr
self . mStartPathStr = inStartPathStr
@ -101,6 +104,8 @@ class Process():
lGS [ " ManagersProcessDict " ] [ ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) ] = self
lGS [ " ManagersProcessDict " ] [ ( inAgentHostNameStr . upper ( ) , inAgentUserNameStr . upper ( ) , inProcessNameWOExeStr . upper ( ) ) ] = self
lActivityDict = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = self . StatusCheck , inArgList = [ ] , inThreadBool = True )
lActivityDict = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = self . StatusCheck , inArgList = [ ] , inThreadBool = True )
__Orchestrator__ . ProcessorActivityItemAppend ( inActivityItemDict = lActivityDict )
__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) " )
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 :
@ -163,7 +168,7 @@ class Process():
if lLogBool == True : self . StatusChangeLog ( )
if lLogBool == True : self . StatusChangeLog ( )
return self . mStatusStr
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 .
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
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 )
__Orchestrator__ . OrchestratorLoggerGet ( ) . warning ( lStr )
return self . mStatusStr
return self . mStatusStr
# Send activity item to agent - wait result
# Send activity item to agent - wait result
if self . mStartPathStr is not None : lCMDStr = f " start { os . path . abspath ( self . mStartPathStr ) } "
if self . mStartPathStr is not None : lCMDStr = os . path . abspath ( self . mStartPathStr )
elif self . mStartCMDStr is not None : lCMDStr = f " start { self . mStartCMDStr } "
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
#import pdb
#pdb.set_trace()
#pdb.set_trace()
self . MuteWait ( )
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. " )
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
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 ) :
def StatusRestore ( self ) :
"""
"""
Execute the StatusCheck , after that restore status to the saved state ( see StatusSave ) . Work when orchestrator is restarted .
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
self . StatusCheck ( ) # check current status
# Do some action
# Do some action
if self . mStatusSavedStr != self . mStatusStr and self . mStatusSavedStr is not None :
if self . mStatusSavedStr != self . mStatusStr and self . mStatusSavedStr is not None :
lManualBool = False
#lManualBool = False
if " MANUAL " in self . mStatusSavedStr :
#if "MANUAL" in self.mStatusSavedStr :
lManualBool = True
# lManualBool = True
if " STOPPED " in self . mStatusSavedStr and " STOPPED " not in self . mStatusStr :
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 :
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 } " )
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
self . mStatusSavedStr = None
return self . mStatusStr
return self . mStatusStr