From c369c70b800a43a9b5d2496699bf24168372977a Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Thu, 30 Jul 2020 17:02:50 +0300 Subject: [PATCH] # Add struct to load SettingsUpdate after RDP restore --- .../Settings/SettingsOrchestratorExample.py | 1 + .../Orchestrator/BackwardCompatibility.py | 8 +++++--- Sources/pyOpenRPA/Orchestrator/Orchestrator.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Orchestrator/Settings/SettingsOrchestratorExample.py b/Orchestrator/Settings/SettingsOrchestratorExample.py index 32384138..52030f51 100644 --- a/Orchestrator/Settings/SettingsOrchestratorExample.py +++ b/Orchestrator/Settings/SettingsOrchestratorExample.py @@ -176,6 +176,7 @@ def Settings(): ] }, "OrchestratorStart":{ + "DefSettingsUpdatePathList":[], # List of the .py files which should be loaded before init the algorythms "ActivityList":[ #{ # "Type": "ProcessStop", #Activity type diff --git a/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py b/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py index fadf0d3a..763119c8 100644 --- a/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py +++ b/Sources/pyOpenRPA/Orchestrator/BackwardCompatibility.py @@ -33,9 +33,11 @@ def Update(inGSettings): } } } - if lL: lL.warning( - f"Backward compatibility (v1.1.13 to v1.1.14): Add default 'Client' structure") # Log about compatibility + if lL: lL.warning(f"Backward compatibility (v1.1.13 to v1.1.14): Add default 'Client' structure") # Log about compatibility if "RequestTimeoutSecFloat" not in inGSettings["Server"]: # Add Server > "RequestTimeoutSecFloat" property inGSettings["Server"]["RequestTimeoutSecFloat"] = 300 # Time to handle request in seconds if lL: lL.warning( - f"Backward compatibility (v1.1.13 to v1.1.14): Add default 'Server' > 'RequestTimeoutSecFloat' property") # Log about compatibility \ No newline at end of file + f"Backward compatibility (v1.1.13 to v1.1.14): Add default 'Server' > 'RequestTimeoutSecFloat' property") # Log about compatibility + if "DefSettingsUpdatePathList" not in inGSettings["OrchestratorStart"]: # Add OrchestratorStart > "DefSettingsUpdatePathList" property + inGSettings["OrchestratorStart"]["DefSettingsUpdatePathList"] = [] # List of the .py files which should be loaded before init the algorythms + if lL: lL.warning(f"Backward compatibility (v1.1.13 to v1.1.14): Add default 'OrchestratorStart' > 'DefSettingsUpdatePathList' property list") # Log about compatibility \ No newline at end of file diff --git a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py index 7ab4bd07..7ea775cb 100644 --- a/Sources/pyOpenRPA/Orchestrator/Orchestrator.py +++ b/Sources/pyOpenRPA/Orchestrator/Orchestrator.py @@ -83,6 +83,23 @@ lDaemonActivityLogDict={} #Словарь отработанных активн lDaemonLastDateTime=datetime.datetime.now() gSettingsDict["Server"]["WorkingDirectoryPathStr"] = os.getcwd() # Set working directory in g settings +# Init SettingsUpdate defs from file list (after RDP restore) +lSettingsUpdateFilePathList = gSettingsDict.get("OrchestratorStart", {}).get("DefSettingsUpdatePathList",[]) +lSubmoduleFunctionName = "SettingsUpdate" +lSettingsPath = "\\".join(os.path.join(os.getcwd(), __file__).split("\\")[:-1]) +for lModuleFilePathItem in lSettingsUpdateFilePathList: # Import defs with try catch + try: # Try to init - go next if error and log in logger + lModuleName = lModuleFilePathItem[0:-3] + lFileFullPath = os.path.join(lSettingsPath, lModuleFilePathItem) + lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) + lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) + lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) + if lSubmoduleFunctionName in dir(lTechModuleFromSpec): + # Run SettingUpdate function in submodule + getattr(lTechModuleFromSpec, lSubmoduleFunctionName)(gSettingsDict) + except Exception as e: + if lL: lL.exception(f"Error when init .py file in orchestrator '{lModuleFilePathItem}'. Exception is below:") + # Turn on backward compatibility BackwardCompatibility.Update(inGSettings= gSettingsDict)