@ -75,7 +75,6 @@ def AgentActivityItemExists(inGSettings, inHostNameStr, inUserStr, inGUIDStr):
lAgentDictItemKeyTurple = ( inHostNameStr . upper ( ) , inUserStr . upper ( ) )
lResultBool = False
if lAgentDictItemKeyTurple in inGSettings [ " AgentDict " ] :
inGSettings [ " AgentDict " ] [ lAgentDictItemKeyTurple ] = SettingsTemplate . __AgentDictItemCreate__ ( )
for lActivityItem in inGSettings [ " AgentDict " ] [ lAgentDictItemKeyTurple ] [ " ActivityList " ] :
if inGUIDStr == lActivityItem . get ( " GUIDStr " , None ) :
lResultBool = True
@ -144,6 +143,7 @@ def AgentOSFileSend(inGSettings, inHostNameStr, inUserStr, inOrchestratorFilePat
"""
Send the file from the Orchestrator to Agent ( synchroniously ) pyOpenRPA . Agent daemon process ( safe for JSON transmition ) .
Work safety with big files
Thread safe - you can call def even if you dont init the orchestrator - def will be executed later
: param inGSettings : Global settings dict ( singleton )
: param inHostNameStr :
@ -152,41 +152,58 @@ def AgentOSFileSend(inGSettings, inHostNameStr, inUserStr, inOrchestratorFilePat
: param inFileDataBytes :
: return : GUID String of the ActivityItem - you can wait ( sync or async ) result by this guid !
"""
lActivityItemCheckIntervalSecFloat = inGSettings [ " ServerDict " ] [ " AgentFileChunkCheckIntervalSecFloat " ]
# Get the chunk limit
lChunkByteSizeInt = inGSettings [ " ServerDict " ] [ " AgentFileChunkBytesSizeInt " ]
lL = inGSettings . get ( " Logger " , None )
# Open the file and get the size (in bytes)
lFile = open ( inOrchestratorFilePathStr , " rb " )
lFileSizeBytesInt = lFile . seek ( 0 , 2 )
lFile . seek ( 0 )
lChunkCountInt = math . ceil ( lFileSizeBytesInt / lChunkByteSizeInt )
if lL : lL . info ( f " O2A: Start to send binary file via chunks. Chunk count: { lChunkCountInt } , From (Orch side): { inOrchestratorFilePathStr } , To (Agent side): { inAgentFilePathStr } " )
for lChunkNumberInt in range ( lChunkCountInt ) :
# Read chunk
lFileChunkBytes = lFile . read ( lChunkByteSizeInt )
# Convert to base64
lFileChunkBase64Str = base64 . b64encode ( lFileChunkBytes ) . decode ( " utf-8 " )
# Send chunk
if lChunkNumberInt == 0 :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrCreate ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
else :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrAppend ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
# Wait for the activity will be deleted
while AgentActivityItemExists ( inGSettings = inGSettings , inHostNameStr = inHostNameStr , inUserStr = inUserStr , inGUIDStr = lActivityItemGUIDStr ) :
time . sleep ( lActivityItemCheckIntervalSecFloat )
if lL : lL . debug (
f " O2A: BINARY SEND: Current chunk index: { lChunkNumberInt } " )
# Close the file
lFile . close ( )
# Check thread
if inGSettings [ " ServerDict " ] [ " ServerThread " ] is None :
if inGSettings [ " Logger " ] : inGSettings [ " Logger " ] . warning ( f " AgentOSFileSend run before server init - activity will be append in the processor queue. " )
lResult = {
" Def " : AgentOSFileSend , # def link or def alias (look gSettings["Processor"]["AliasDefDict"])
" ArgList " : [ ] , # Args list
" ArgDict " : { " inHostNameStr " : inHostNameStr , " inUserStr " : inUserStr , " inOrchestratorFilePathStr " : inOrchestratorFilePathStr , " inAgentFilePathStr " : inAgentFilePathStr } , # Args dictionary
" ArgGSettings " : " inGSettings " , # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
" ArgLogger " : None # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
}
inGSettings [ " ProcessorDict " ] [ " ActivityList " ] . append ( lResult )
else : # In processor - do execution
lActivityItemCheckIntervalSecFloat = inGSettings [ " ServerDict " ] [ " AgentFileChunkCheckIntervalSecFloat " ]
# Get the chunk limit
lChunkByteSizeInt = inGSettings [ " ServerDict " ] [ " AgentFileChunkBytesSizeInt " ]
lL = inGSettings . get ( " Logger " , None )
# Open the file and get the size (in bytes)
lFile = open ( inOrchestratorFilePathStr , " rb " )
lFileSizeBytesInt = lFile . seek ( 0 , 2 )
lFile . seek ( 0 )
#import pdb
#pdb.set_trace()
lChunkCountInt = math . ceil ( lFileSizeBytesInt / lChunkByteSizeInt )
if lL : lL . info ( f " O2A: Start to send binary file via chunks. Chunk count: { lChunkCountInt } , From (Orch side): { inOrchestratorFilePathStr } , To (Agent side): { inAgentFilePathStr } " )
for lChunkNumberInt in range ( lChunkCountInt ) :
# Read chunk
lFileChunkBytes = lFile . read ( lChunkByteSizeInt )
# Convert to base64
lFileChunkBase64Str = base64 . b64encode ( lFileChunkBytes ) . decode ( " utf-8 " )
# Send chunk
if lChunkNumberInt == 0 :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrCreate ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
else :
lActivityItemGUIDStr = AgentOSFileBinaryDataBase64StrAppend ( inGSettings = inGSettings , inHostNameStr = inHostNameStr ,
inUserStr = inUserStr , inFilePathStr = inAgentFilePathStr ,
inFileDataBase64Str = lFileChunkBase64Str )
# Wait for the activity will be deleted
while AgentActivityItemExists ( inGSettings = inGSettings , inHostNameStr = inHostNameStr , inUserStr = inUserStr , inGUIDStr = lActivityItemGUIDStr ) :
time . sleep ( lActivityItemCheckIntervalSecFloat )
if lL : lL . debug (
f " O2A: BINARY SEND: Current chunk index: { lChunkNumberInt } " )
if lL : lL . info (
f " O2A: BINARY SEND: Transmition has been complete " )
# Close the file
lFile . close ( )
def AgentOSFileBinaryDataBytesCreate ( inGSettings , inHostNameStr , inUserStr , inFilePathStr , inFileDataBytes ) :
"""
@ -2131,6 +2148,7 @@ def Orchestrator(inGSettings, inDumpRestoreBool = True, inRunAsAdministratorBool
lItemDict = lListenDict [ lItemKeyStr ]
lThreadServer = Server . RobotDaemonServer ( lItemKeyStr , gSettingsDict )
lThreadServer . start ( )
gSettingsDict [ " ServerDict " ] [ " ServerThread " ] = lThreadServer
lItemDict [ " ServerInstance " ] = lThreadServer
# Init the RobotScreenActive in another thread