Add pause trigger to RDPActive when Processor is working!

dev-linux
Ivan Maslov 4 years ago
parent 1f1eaf027c
commit b149647594

@ -1,7 +1,8 @@
# 1.2.0 - general processor - contains old orchestrator processor + RDPActive processor # 1.2.0 - general processor - contains old orchestrator processor + RDPActive processor
import time, copy, threading import time, copy, threading
# Run processor synchronious # Run processor synchronious
def ProcessorRunSync(inGSettings): # inThreadControlDict = {"ThreadExecuteBool":True}
def ProcessorRunSync(inGSettings, inRobotRDPThreadControlDict):
""" """
"ProcessorDict": { # Has been changed. New general processor (one threaded) v.1.2.0 "ProcessorDict": { # Has been changed. New general processor (one threaded) v.1.2.0
"ActivityList": [ # List of the activities "ActivityList": [ # List of the activities
@ -24,7 +25,9 @@ def ProcessorRunSync(inGSettings):
if len(lActivityList)>0: if len(lActivityList)>0:
if lL: lL.debug(f'Processor ActivityList len: {len(lActivityList)}') if lL: lL.debug(f'Processor ActivityList len: {len(lActivityList)}')
lActivityItem = inGSettings["ProcessorDict"]["ActivityList"].pop(0) # Extract the first item from processor queue lActivityItem = inGSettings["ProcessorDict"]["ActivityList"].pop(0) # Extract the first item from processor queue
inRobotRDPThreadControlDict["ThreadExecuteBool"]=False # Stop the RobotRDPActive monitoring
ActivityListExecute(inGSettings = inGSettings, inActivityList = [lActivityItem]) # execute the activity item ActivityListExecute(inGSettings = inGSettings, inActivityList = [lActivityItem]) # execute the activity item
inRobotRDPThreadControlDict["ThreadExecuteBool"] = True # Continue the RobotRDPActive monitoring
else: else:
time.sleep(inGSettings["ProcessorDict"]["CheckIntervalSecFloat"]) # Sleep when list is empty time.sleep(inGSettings["ProcessorDict"]["CheckIntervalSecFloat"]) # Sleep when list is empty

@ -5,7 +5,8 @@ from . import ConnectorExceptions # Exceptions classes
from . import Connector from . import Connector
from . import Processor # Module for process some functions on thr RDP from . import Processor # Module for process some functions on thr RDP
# Main function # Main function
def RobotRDPActive(inGSettings): # inThreadControlDict = {"ThreadExecuteBool":True}
def RobotRDPActive(inGSettings, inThreadControlDict):
# inGSettings = { # inGSettings = {
# ... "RobotRDPActive": {} ... # ... "RobotRDPActive": {} ...
# } # }
@ -36,100 +37,88 @@ def RobotRDPActive(inGSettings):
lResponsibilityCheckLastSec = time.time() # Get current time for check interval lResponsibilityCheckLastSec = time.time() # Get current time for check interval
while lFlagWhile: while lFlagWhile:
try: try:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if inThreadControlDict["ThreadExecuteBool"] == True:
# Check RDP window is OK - reconnect if connection was lost # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
lUIOSelectorList = [] # Check RDP window is OK - reconnect if connection was lost
lRDPConfigurationDictList = [] lUIOSelectorList = []
# Prepare selectors list for check lRDPConfigurationDictList = []
for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]: # Prepare selectors list for check
lItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem]
lRDPConfigurationDictList.append(lItem) # Add RDP Configuration in list
lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']}.*", "backend": "win32"}])
# Run wait command
lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout)
for lItem in lRDPDissappearList: # Reconnect if connection was lost
lRDPConfigurationDict = lRDPConfigurationDictList[lItem] # Get RDP Configuration list
lRDPConfigurationDict["SessionIsWindowExistBool"] = False # Set flag that session is disconnected
# Check if RDP window is not ignored
if not lRDPConfigurationDict["SessionIsIgnoredBool"]:
try:
Connector.Session(lRDPConfigurationDict, inScreenSize550x350Bool = True)
lRDPConfigurationDict["SessionIsWindowExistBool"] = True # Flag that session is started
if lL: lL.info(f"SessionHex: {str(lRDPConfigurationDict['SessionHex'])}:: Session has been initialized!") #Logging
# catch ConnectorExceptions.SessionWindowNotExistError
except ConnectorExceptions.SessionWindowNotExistError as e:
lRDPConfigurationDict["SessionIsWindowExistBool"] = False # Set flag that session is disconnected
if lL: lL.warning(f"SessionHex: {str(lRDPConfigurationDict['SessionHex'])}:: Session is not exist!") #Logging
# general exceptions
except Exception as e:
if lL: lL.exception(f"!!! ATTENTION !!! Unrecognized error") #Logging
pass
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Safe turn off the - no need because of Orchestrator control
#if inGlobalDict.get("OrchestratorToRobotResetStorage", {}).get("SafeTurnOff", False):
# lFlagWhile = False
# # Set status disconnected for all RDP List
# for lItem in inGlobalDict["RDPList"]:
# lItem["SessionIsWindowExistBool"] = False
# lItem["SessionIsWindowResponsibleBool"] = False
# # Kill all RDP sessions
# os.system('taskkill /F /im mstsc.exe')
# # Return from function
# return
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Connector.SystemRDPWarningClickOk() # Click all warning messages
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Check if RDP session is full screen (if is not ignored)
if inGlobalDict["FullScreenRDPSessionKeyStr"] is not None:
lRDPSessionKeyStr = inGlobalDict["FullScreenRDPSessionKeyStr"] # Get the RDPSessionKeyStr
if lRDPSessionKeyStr in inGlobalDict["RDPList"]: # Session Key is in dict
lRDPConfigurationDict = inGlobalDict["RDPList"][lRDPSessionKeyStr]
#if not lRDPConfigurationDict["SessionIsIgnoredBool"]: # Session is not ignored
# Check if full screen
lIsFullScreenBool = Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDict["SessionHex"])
if not lIsFullScreenBool: # If not the full screen
# Check all RDP window and minimize it
for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]:
lRDPConfigurationDictItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem]
if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]):
Connector.SessionScreenSize_X_Y_W_H(inSessionHex=lRDPConfigurationDictItem["SessionHex"], inXInt=10, inYInt=10,
inWInt=550,
inHInt=350) # Prepare little window
# Set full screen for new window
Connector.SessionScreenFull(inSessionHex=lRDPConfigurationDict["SessionHex"], inLogger= inGSettings["Logger"], inRDPConfigurationItem=inGlobalDict["RDPList"][lRDPSessionKeyStrItem])
else:
# Check all RDP window and minimize it
for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]: for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]:
lRDPConfigurationDictItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem] lItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem]
if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]) or Connector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]): # If window is minimized - restore # if window in full screen - resize lRDPConfigurationDictList.append(lItem) # Add RDP Configuration in list
Connector.SessionScreenSize_X_Y_W_H(inSessionHex=lRDPConfigurationDictItem["SessionHex"], lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']}.*", "backend": "win32"}])
inXInt=10, inYInt=10, # Run wait command
inWInt=550, lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout)
inHInt=350) # Prepare little window for lItem in lRDPDissappearList: # Reconnect if connection was lost
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # lRDPConfigurationDict = lRDPConfigurationDictList[lItem] # Get RDP Configuration list
# Iterate the activity list in robot RDP active lRDPConfigurationDict["SessionIsWindowExistBool"] = False # Set flag that session is disconnected
lActivityListNew = [] # Check if RDP window is not ignored
lActivityListOld = inGlobalDict["ActivityList"] if not lRDPConfigurationDict["SessionIsIgnoredBool"]:
inGlobalDict["ActivityList"] = [] try:
for lActivityItem in lActivityListOld: Connector.Session(lRDPConfigurationDict, inScreenSize550x350Bool = True)
lSubmoduleFunctionName = lActivityItem["DefNameStr"] lRDPConfigurationDict["SessionIsWindowExistBool"] = True # Flag that session is started
if lSubmoduleFunctionName in dir(Processor): if lL: lL.info(f"SessionHex: {str(lRDPConfigurationDict['SessionHex'])}:: Session has been initialized!") #Logging
lActivityItemResult = None # init the variable # catch ConnectorExceptions.SessionWindowNotExistError
try: # try to run function from Processor.py except ConnectorExceptions.SessionWindowNotExistError as e:
lActivityItemResult = getattr(Processor, lSubmoduleFunctionName)( lRDPConfigurationDict["SessionIsWindowExistBool"] = False # Set flag that session is disconnected
*lActivityItem["ArgList"], **lActivityItem["ArgDict"]) if lL: lL.warning(f"SessionHex: {str(lRDPConfigurationDict['SessionHex'])}:: Session is not exist!") #Logging
except Exception as e: # general exceptions
if lL: lL.exception(f"RDP::main: Exception when run def in processor.py - activity will be ignored. Activity item: {lActivityItem}") #Logging except Exception as e:
lActivityItemResult = True # True - clear from repeat list if lL: lL.exception(f"!!! ATTENTION !!! Unrecognized error") #Logging
lActivityItemResultType = type(lActivityItemResult) pass
# Check if Result is bool # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if lActivityItemResultType is bool: Connector.SystemRDPWarningClickOk() # Click all warning messages
if not lActivityItemResult: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Activity is not done - add to list (retry in future) # Check if RDP session is full screen (if is not ignored)
lActivityListNew.append(lActivityItem) if inGlobalDict["FullScreenRDPSessionKeyStr"] is not None:
inGlobalDict["ActivityList"] = lActivityListNew # Override the value lRDPSessionKeyStr = inGlobalDict["FullScreenRDPSessionKeyStr"] # Get the RDPSessionKeyStr
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if lRDPSessionKeyStr in inGlobalDict["RDPList"]: # Session Key is in dict
lRDPConfigurationDict = inGlobalDict["RDPList"][lRDPSessionKeyStr]
#if not lRDPConfigurationDict["SessionIsIgnoredBool"]: # Session is not ignored
# Check if full screen
lIsFullScreenBool = Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDict["SessionHex"])
if not lIsFullScreenBool: # If not the full screen
# Check all RDP window and minimize it
for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]:
lRDPConfigurationDictItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem]
if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]):
Connector.SessionScreenSize_X_Y_W_H(inSessionHex=lRDPConfigurationDictItem["SessionHex"], inXInt=10, inYInt=10,
inWInt=550,
inHInt=350) # Prepare little window
# Set full screen for new window
Connector.SessionScreenFull(inSessionHex=lRDPConfigurationDict["SessionHex"], inLogger= inGSettings["Logger"], inRDPConfigurationItem=inGlobalDict["RDPList"][lRDPSessionKeyStrItem])
else:
# Check all RDP window and minimize it
for lRDPSessionKeyStrItem in inGlobalDict["RDPList"]:
lRDPConfigurationDictItem = inGlobalDict["RDPList"][lRDPSessionKeyStrItem]
if Connector.SessionIsFullScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]) or Connector.SessionIsMinimizedScreen(inSessionHexStr=lRDPConfigurationDictItem["SessionHex"]): # If window is minimized - restore # if window in full screen - resize
Connector.SessionScreenSize_X_Y_W_H(inSessionHex=lRDPConfigurationDictItem["SessionHex"],
inXInt=10, inYInt=10,
inWInt=550,
inHInt=350) # Prepare little window
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Iterate the activity list in robot RDP active
lActivityListNew = []
lActivityListOld = inGlobalDict["ActivityList"]
inGlobalDict["ActivityList"] = []
for lActivityItem in lActivityListOld:
lSubmoduleFunctionName = lActivityItem["DefNameStr"]
if lSubmoduleFunctionName in dir(Processor):
lActivityItemResult = None # init the variable
try: # try to run function from Processor.py
lActivityItemResult = getattr(Processor, lSubmoduleFunctionName)(
*lActivityItem["ArgList"], **lActivityItem["ArgDict"])
except Exception as e:
if lL: lL.exception(f"RDP::main: Exception when run def in processor.py - activity will be ignored. Activity item: {lActivityItem}") #Logging
lActivityItemResult = True # True - clear from repeat list
lActivityItemResultType = type(lActivityItemResult)
# Check if Result is bool
if lActivityItemResultType is bool:
if not lActivityItemResult:
# Activity is not done - add to list (retry in future)
lActivityListNew.append(lActivityItem)
inGlobalDict["ActivityList"] = lActivityListNew # Override the value
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
except RuntimeError as e: except RuntimeError as e:
# case noGUI error passed - do nothing # case noGUI error passed - do nothing
if lL: lL.warning(f"Host session has lost the GUI") #Logging if lL: lL.warning(f"Host session has lost the GUI") #Logging

@ -922,7 +922,8 @@ def Orchestrator(inGSettings):
if lL: lL.info("Robot Screen active has been started") #Logging if lL: lL.info("Robot Screen active has been started") #Logging
# Init the RobotRDPActive in another thread # Init the RobotRDPActive in another thread
lRobotRDPActiveThread = threading.Thread(target= RobotRDPActive.RobotRDPActive, kwargs={"inGSettings":gSettingsDict}) lRobotRDPThreadControlDict = {"ThreadExecuteBool":True} # inThreadControlDict = {"ThreadExecuteBool":True}
lRobotRDPActiveThread = threading.Thread(target= RobotRDPActive.RobotRDPActive, kwargs={"inGSettings":gSettingsDict, "inThreadControlDict":lRobotRDPThreadControlDict})
lRobotRDPActiveThread.daemon = True # Run the thread in daemon mode. lRobotRDPActiveThread.daemon = True # Run the thread in daemon mode.
lRobotRDPActiveThread.start() # Start the thread execution. lRobotRDPActiveThread.start() # Start the thread execution.
if lL: lL.info("Robot RDP active has been started") #Logging if lL: lL.info("Robot RDP active has been started") #Logging
@ -939,7 +940,7 @@ def Orchestrator(inGSettings):
Processor.ActivityListOrDict(lActivityItem) Processor.ActivityListOrDict(lActivityItem)
# Processor thread # Processor thread
lProcessorThread = threading.Thread(target= Processor.ProcessorRunSync, kwargs={"inGSettings":gSettingsDict}) lProcessorThread = threading.Thread(target= Processor.ProcessorRunSync, kwargs={"inGSettings":gSettingsDict, "inRobotRDPThreadControlDict":lRobotRDPThreadControlDict})
lProcessorThread.daemon = True # Run the thread in daemon mode. lProcessorThread.daemon = True # Run the thread in daemon mode.
lProcessorThread.start() # Start the thread execution. lProcessorThread.start() # Start the thread execution.
if lL: lL.info("Processor has been started (ProcessorDict)") #Logging if lL: lL.info("Processor has been started (ProcessorDict)") #Logging

Loading…
Cancel
Save