|
|
|
@ -330,7 +330,8 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings):
|
|
|
|
|
# See docs in Agent (pyOpenRPA.Agent.O2A)
|
|
|
|
|
def pyOpenRPA_Agent_O2A(inRequest, inGSettings):
|
|
|
|
|
lL = inGSettings["Logger"] # Alias
|
|
|
|
|
lConnectionLifetimeSecFloat = 3600.0 # 60 min * 60 sec 3600.0
|
|
|
|
|
lConnectionLifetimeSecFloat = 300.0 # 5 min * 60 sec 300.0
|
|
|
|
|
lActivityItemLifetimeLimitSecFloat = 30.0 # # 30 seconds
|
|
|
|
|
lTimeStartFloat = time.time()
|
|
|
|
|
# Recieve the data
|
|
|
|
|
lValueStr = None
|
|
|
|
@ -348,32 +349,51 @@ def pyOpenRPA_Agent_O2A(inRequest, inGSettings):
|
|
|
|
|
lThisAgentDict["ConnectionCountInt"] += 1 # increment connection count
|
|
|
|
|
# Test solution
|
|
|
|
|
lDoLoopBool = True
|
|
|
|
|
while lDoLoopBool:
|
|
|
|
|
# Check if lifetime is over
|
|
|
|
|
if time.time() - lTimeStartFloat > lConnectionLifetimeSecFloat: # Lifetime is over
|
|
|
|
|
lThisAgentDict["IsListenBool"] = False # Set is offline
|
|
|
|
|
lDoLoopBool = False
|
|
|
|
|
else: # Lifetime is good - do alg
|
|
|
|
|
lThisAgentDict["IsListenBool"] = True # Set is online
|
|
|
|
|
lQueueList = lThisAgentDict["ActivityList"]
|
|
|
|
|
if len(lQueueList)>0:# Do some operations if has queue items
|
|
|
|
|
if lL: lL.debug(f'O2A BEFORE: ConnectionCountInt: {lThisAgentDict["ConnectionCountInt"]};ConnectionFirstQueueItemCountInt {lThisAgentDict["ConnectionFirstQueueItemCountInt"]}')
|
|
|
|
|
if lThisAgentDict["ConnectionCountInt"] == lThisAgentDict["ConnectionFirstQueueItemCountInt"] + 1:
|
|
|
|
|
# POP QUEUE ITEM CONDITION ConnectionCountInt == ConnectionFirstQueueItemCountInt + 1
|
|
|
|
|
lActivityItem = lThisAgentDict["ActivityList"].pop(0)
|
|
|
|
|
lThisAgentDict["ConnectionFirstQueueItemCountInt"] = 0
|
|
|
|
|
if lL: lL.debug(f"Activity was deleted from the list: {lThisAgentDict['ActivityList']}")
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
while lDoLoopBool:
|
|
|
|
|
# Check if lifetime is over
|
|
|
|
|
if time.time() - lTimeStartFloat > lConnectionLifetimeSecFloat: # Lifetime is over
|
|
|
|
|
lThisAgentDict["IsListenBool"] = False # Set is offline
|
|
|
|
|
lDoLoopBool = False
|
|
|
|
|
else: # Lifetime is good - do alg
|
|
|
|
|
lThisAgentDict["IsListenBool"] = True # Set is online
|
|
|
|
|
lQueueList = lThisAgentDict["ActivityList"]
|
|
|
|
|
if len(lQueueList)>0:# Do some operations if has queue items
|
|
|
|
|
if lL: lL.debug(f'O2A: ConnectionCountInt: {lThisAgentDict["ConnectionCountInt"]};ConnectionFirstQueueItemCountInt {lThisAgentDict["ConnectionFirstQueueItemCountInt"]}')
|
|
|
|
|
# check if delta datetime is < than ActivityLifeTimeSecFloat
|
|
|
|
|
lActivityItem = lThisAgentDict["ActivityList"][0]
|
|
|
|
|
lThisAgentDict["ConnectionFirstQueueItemCountInt"] += 1
|
|
|
|
|
if lL: lL.debug(f"Activity was !not! deleted from the list: {lThisAgentDict['ActivityList']}")
|
|
|
|
|
if lL: lL.debug(f'O2A AFTER: ConnectionCountInt: {lThisAgentDict["ConnectionCountInt"]};ConnectionFirstQueueItemCountInt {lThisAgentDict["ConnectionFirstQueueItemCountInt"]}')
|
|
|
|
|
# Send QUEUE ITEM
|
|
|
|
|
if lL: lL.info(f"Activity item to agent Hostname {lInput['HostNameUpperStr']}, User {lInput['UserUpperStr']}. Activity item: {lActivityItem}")
|
|
|
|
|
inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lActivityItem), "utf8")
|
|
|
|
|
lDoLoopBool = False # CLose the connection
|
|
|
|
|
else: # no queue item - sleep for the next iteration
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
lActivityLifetimeSecFloat = (datetime.datetime.now() - lActivityItem["CreatedByDatetime"]).total_seconds()
|
|
|
|
|
# Check case if limit is expired - remove item
|
|
|
|
|
if lActivityLifetimeSecFloat > lActivityItemLifetimeLimitSecFloat:
|
|
|
|
|
lActivityItem = lThisAgentDict["ActivityList"].pop(0)
|
|
|
|
|
else:
|
|
|
|
|
lReturnActivityItemDict = None
|
|
|
|
|
# If lInput['ActivityLastGUIDStr'] is '' > return 0 element for send in Agent
|
|
|
|
|
if lInput['ActivityLastGUIDStr'] == "":
|
|
|
|
|
lReturnActivityItemDict = lActivityItem[0]
|
|
|
|
|
else:
|
|
|
|
|
# go from the end - search element with GUIDStr
|
|
|
|
|
lForTriggerGetNextItem = False
|
|
|
|
|
for lForActivityItemDict in lQueueList:
|
|
|
|
|
if lForTriggerGetNextItem == True:
|
|
|
|
|
lReturnActivityItemDict = lForActivityItemDict
|
|
|
|
|
break
|
|
|
|
|
if lForActivityItemDict['GUIDStr'] == lInput['ActivityLastGUIDStr']: lForTriggerGetNextItem = True
|
|
|
|
|
# CASE if GUID is not detected - return 0 element
|
|
|
|
|
if lReturnActivityItemDict == None and lForTriggerGetNextItem == False:
|
|
|
|
|
lReturnActivityItemDict = lActivityItem[0]
|
|
|
|
|
# Send QUEUE ITEM
|
|
|
|
|
if lReturnActivityItemDict is not None:
|
|
|
|
|
lReturnActivityItemDict = copy.deepcopy(lReturnActivityItemDict)
|
|
|
|
|
if "CreatedByDatetime" in lReturnActivityItemDict:
|
|
|
|
|
del lReturnActivityItemDict["CreatedByDatetime"]
|
|
|
|
|
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: # no queue item - sleep for the next iteration
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
pass
|
|
|
|
|
lThisAgentDict["ConnectionCountInt"] -= 1 # Connection go to be closed - decrement the connection count
|
|
|
|
|
# See docs in Agent (pyOpenRPA.Agent.A2O)
|
|
|
|
|
def pyOpenRPA_Agent_A2O(inRequest, inGSettings):
|
|
|
|
|