From 24849e7deac1220bf502c75384593cb0243f14cd Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Mon, 26 Apr 2021 17:31:50 +0300 Subject: [PATCH] Orchestrator - fix in Agent loop - add sleep when Activity is not empty but this is alredy sent Add parameters in settings to manipulate Agent performance --- .../Orchestrator/BackwardCompatibility.py | 7 +++ .../pyOpenRPA/Orchestrator/ServerSettings.py | 9 ++- .../Orchestrator/SettingsTemplate.py | 57 +++++-------------- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py b/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py index bef5a0e9..d853692e 100644 --- a/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py +++ b/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py @@ -434,3 +434,10 @@ def Update(inGSettings): inGSettings["ProcessorDict"]["WarningExecutionMoreThanSecFloat"] = 60.0 if lL: lL.warning( f"Backward compatibility (v1.2.1 to v1.2.2): Add key WarningExecutionMoreThanSecFloat in ProcessorDict") # Log about compatibility + # Add new key AgentActivityLifetimeSecFloat, AgentConnectionLifetimeSecFloat, AgentLoopSleepSecFloat in ProcessorDict > ServerDict + if "AgentActivityLifetimeSecFloat" not in inGSettings["ServerDict"]: + inGSettings["ServerDict"]["AgentActivityLifetimeSecFloat"] = 1200.0 + inGSettings["ServerDict"]["AgentConnectionLifetimeSecFloat"] = 300.0 + inGSettings["ServerDict"]["AgentLoopSleepSecFloat"] = 2.0 + if lL: lL.warning( + f"Backward compatibility (v1.2.1 to v1.2.2): Add key AgentActivityLifetimeSecFloat, AgentConnectionLifetimeSecFloat, AgentLoopSleepSecFloat in ProcessorDict > ServerDict") # Log about compatibility diff --git a/Sources/pyOpenRPA/Orchestrator/ServerSettings.py b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py index 10e29ff5..da236626 100644 --- a/Sources/pyOpenRPA/Orchestrator/ServerSettings.py +++ b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py @@ -333,8 +333,9 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings): # See docs in Agent (pyOpenRPA.Agent.O2A) def pyOpenRPA_Agent_O2A(inRequest, inGSettings): lL = inGSettings["Logger"] # Alias - lConnectionLifetimeSecFloat = 300.0 # 5 min * 60 sec 300.0 - lActivityItemLifetimeLimitSecFloat = 30.0 # # 30 seconds + lConnectionLifetimeSecFloat = inGSettings["ServerDict"]["AgentConnectionLifetimeSecFloat"] # 300.0 # 5 min * 60 sec 300.0 + lActivityItemLifetimeLimitSecFloat = inGSettings["ServerDict"]["AgentActivityLifetimeSecFloat"] + lAgentLoopSleepSecFloat = inGSettings["ServerDict"]["AgentLoopSleepSecFloat"] lTimeStartFloat = time.time() # Recieve the data lValueStr = None @@ -393,8 +394,10 @@ def pyOpenRPA_Agent_O2A(inRequest, inGSettings): if lL: lL.info(f"Activity item to agent Hostname {lInput['HostNameUpperStr']}, User {lInput['UserUpperStr']}. Activity item: {lReturnActivityItemDict}") inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lReturnActivityItemDict), "utf8") lDoLoopBool = False # CLose the connection + else: # Nothing to send - sleep for the next iteration + time.sleep(lAgentLoopSleepSecFloat) else: # no queue item - sleep for the next iteration - time.sleep(1) + time.sleep(lAgentLoopSleepSecFloat) except Exception as e: if lL: lL.exception("pyOpenRPA_Agent_O2A Exception!") lThisAgentDict["ConnectionCountInt"] -= 1 # Connection go to be closed - decrement the connection count diff --git a/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py b/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py index 80419880..5afc76a2 100644 --- a/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py +++ b/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py @@ -39,6 +39,9 @@ def __Create__(): # # # # # # # # # # # # # # # # # # }, "ServerDict": { + "AgentActivityLifetimeSecFloat": 1200.0, # Time in seconds to life for activity for the agent + "AgentConnectionLifetimeSecFloat": 300.0, # Time in seconds to handle the open connection to the Agent + "AgentLoopSleepSecFloat": 2.0, # Time in seconds to sleep between loops when check to send some activity to the agent "WorkingDirectoryPathStr": None, # Will be filled automatically "RequestTimeoutSecFloat": 300, # Time to handle request in seconds "ListenPort_": "Порт, по которому можно подключиться к демону", @@ -116,45 +119,7 @@ def __Create__(): "OrchestratorStart": { "DefSettingsUpdatePathList": [], # List of the .py files which should be loaded before init the algorythms - "ActivityList": [ - # { - # "Type": "ProcessStop", #Activity type - # "Name": "OpenRPARobotDaemon.exe", #Process name - # "FlagForce": True, #Force process close - # "User": "%username%" #Empty, user or %username% - # }, - # { - # "Type": "ProcessStartIfTurnedOff", #Activity type - # "CheckTaskName": "notepad.exe", #Python function module name - # "Path": "notepad", #Python function name - # "ArgList": [] #Input python function args - # }, - # { - # "Type": "RDPSessionConnect", #Activity type - start/connect RDP Session - # "RDPSessionKeyStr": "notepad.exe", #Python function module name - # "RDPConfigurationDict": {} - # }, - # { - # "Type": "RDPSessionLogoff", #Activity type - logoff RDP Session - # "RDPSessionKeyStr": "notepad.exe", #Python function module name - # }, - # { - # "Type": "RDPSessionDisconnect", #Activity type - disconnect the RDP Session without logoff - # "RDPSessionKeyStr": "notepad.exe", #Python function module name - # }, - # { - # "Type": "RDPSessionFileSend", #Activity type - send file to RDP session - # ... - # }, - # { - # "Type": "RDPSessionFileRecieve", #Activity type - recieve file from rdp session - # ... - # }, - # { - # "Type": "RDPSessionProcessStart", #Activity type - - # ... - # }, - ] + "ActivityList": [] }, "SchedulerDict": { "CheckIntervalSecFloat": 5.0, # Check interval in seconds @@ -163,11 +128,14 @@ def __Create__(): # "TimeHH:MMStr": "22:23", # Time [HH:MM] to trigger activity # "WeekdayList": [0, 1, 2, 3, 4, 5, 6], #List of the weekday index when activity is applicable, Default [0,1,2,3,4,5,6] # "ActivityList": [ - # { - # "Type": "ProcessStart", # Activity type - # "Path": "start", # Executable file path - # "ArgList": ["cmd.exe", "/c", "PIPUpgrade.cmd"] # List of the arguments - # } + # # { + # # "Def":"DefAliasTest", # def link or def alias (look gSettings["Processor"]["AliasDefDict"]) + # # "ArgList":[1,2,3], # Args list + # # "ArgDict":{"ttt":1,"222":2,"dsd":3} # Args dictionary + # # "ArgGSettings": # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + # # "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + # # "GUIDStr": ..., # GUID of the activity + # # }, # ], # "GUID": None # Will be filled in Orchestrator automatically - is needed for detect activity completion # }, @@ -181,6 +149,7 @@ def __Create__(): # "ArgDict":{"ttt":1,"222":2,"dsd":3} # Args dictionary # "ArgGSettings": # Name of GSettings attribute: str (ArgDict) or index (for ArgList) # "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + # "GUIDStr": ..., # GUID of the activity # }, ], "AliasDefDict": {}, # Storage for def with Str alias. To use it see pyOpenRPA.Orchestrator.ControlPanel