Algorithm of the Python Framework#
The Python framework script, launched via the Windows Scheduler, must follow the following algorithm:
- Perform an HTTP POST request to the
/api/robot/heartbeatscript of the Orchestrator. Pass the following parameters:- The GUID of this Robot (RobotGUID),
- The name of the computer (Machine),
- The IP address of the machine (IP),
- The MAC address of the machine (MAC),
- The current status of the Robot (Status),
- The GUID of the currently executing Job (JobGUID),
- The name of the currently executing Job (JobName),
- The type of Job (JobType, must always be of type Orchestrated, value 1).
Output data (in JSON format):
- HeartbeatErrorCode,
- ErrorText,
- HasNewJob.
The script may return other parameters in the response that are not used in the context of the current Task.
Robot status reference:
Status_Disconnected = 0; # robot is disconnected
Status_Unlicensed = 1; # robot is unlicensed
Status_Ready = 2; # robot is not performing jobs and is ready to accept new jobs
Status_Working = 3; # robot is performing the current job
ErrorCode values reference:
HeartbeatErrorCode_NoError = 0; # no errors
HeartbeatErrorCode_RobotNotFound = 101; # robot with the specified GUID not found
HeartbeatErrorCode_JobAborting = 10; # the orchestrator requested a hard stop of this script (Abort)
HeartbeatErrorCode_JobStopping = 20; # the orchestrator requested a soft stop of this script (Stop)
HasNewJob values reference:
HasNewJob_NoJob = 0 # there are no new jobs for this robot
HasNewJob_JobFound = 1 # there are new jobs for this robot that need to be retrieved using the ConsumeNextJob call
When the script is first run, it is necessary to pass the value Status = 2 (Status_Ready). Also, during the first run, when the name and GUID of the executing job are still unknown, these fields may remain empty.
Example call:
import requests
import base64
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
host = 'http://192.168.1.111:4500' #orchestrator host
robot_guid = 'da8bc2f0-8065-4385-b867-405e66b8e151' #robot GUID
headers = {
'Authorization': 'Basic ' + base64.b64encode(robot_guid.encode('utf-8')).decode('utf-8')
}
req = {
'RobotGUID': robot_guid, #robot GUID
'Machine': robot_machine, #Machine name
'IP': robot_ip, #Robot IP address
'MAC': robot_mac, #Robot MAC address
'Status': 2, #robot status
'JobGUID': '', #Job GUID
'JobName': '', #name of the executing script, i.e., python_script_name hereafter
'JobType': 1 #job type, always value 1
}
r = requests.post(host + '/api/robot/heartbeat', data=req, headers=headers, verify=False)
heartbeat_results = json.loads(r.text)
print(heartbeat_results['HeartbeatErrorCode'])
print(heartbeat_results['ErrorText'])
print(heartbeat_results['HasNewJob'])
If the response is
HasNewJob == 0, terminate the execution of the framework script and log off from the Windows account using Log off.
If the response isHasNewJob == 1, perform an HTTP POST request to the/api/robot/consumeNextJobscript of the Orchestrator.
Input data:- Robot GUID (RobotGUID),
- Current status of the Robot (Status).
Output data (in JSON format):- ConsumeJobErrorCode,
- ErrorText,
- Job,
- ProcessVersion,
- Task.
ConsumeJobErrorCode values reference:
ConsumeJobErrorCode = 0; # no errors
ConsumeJobErrorCode = 101; # robot with the specified GUID not found
ConsumeJobErrorCode = 102; # new job not found
Example call:
import requests
import base64
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
host = 'http://192.168.1.111:4500' #orchestrator host
robot_guid = 'da8bc2f0-8065-4385-b867-405e66b8e151' #robot GUID
headers = {
'Authorization': 'Basic ' + base64.b64encode(robot_guid.encode('utf-8')).decode('utf-8')
}
cnj = {
'RobotGUID': robot_guid #robot GUID
}
r = requests.post(host + '/api/robot/consumeNextJob', data=cnj, headers=headers, verify=False)
consume_result = json.loads(r.text)
print(consume_result['ConsumeJobErrorCode'])
print(consume_result['ErrorText'])
new_job = json.loads(consume_result['Job'])
job_guid = new_job['GUID']
process_version = json.loads(consume_result['ProcessVersion'])
python_script_name = process_version['Name'] #Assuming that the name of the robot script to be executed is passed in the process version name
task = json.loads(consume_result[' Task '])In case of successfully receiving a new Job from the Orchestrator, perform an HTTP PUT request to the
/api/job/updatescript of the Orchestrator. Pass the GUID of the received Job (guid) and the new Job statusStatus_In_Progress.
Job status values reference:Status_Created = 0; #Job createdStatus_Pending = 1; #Job is waiting for the robot to take it onStatus_Aborting = 2; #Job is in the process of hard stopping (interrupting)Status_Aborted = 3; #Job has been successfully interruptedStatus_Success = 4; #Job has been successfully completedStatus_Failed = 5; #Job has not been successfully completedStatus_Stopping = 6; #Job is in the process of soft stoppingStatus_Stopped = 7; #Job has been successfully stopped after a soft stop requestStatus_In_Progress = 8; #Job is currently being executed
Example call:import requestsimport base64import jsonfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)host = 'http://192.168.1.111:4500' #orchestrator hostrobot_guid = 'da8bc2f0-8065-4385-b867-405e66b8e151' #robot GUIDheaders = {
'Authorization': 'Basic ' + base64.b64encode(robot_guid.encode('utf-8')).decode('utf-8')}job = {
'guid': job_guid, #GUID of the current job
'status': 8 #new job status}r = requests.put(host + '/api/job/update', data=job, headers=headers, verify=False)print(r.text)Start executing the Python script of the Robot with the name equal to
python_script_name. If possible, periodically repeat requests to the/api/robot/heartbeatscript with the correct values forJobGUIDandStatus = 3 (Status_Working).
It is recommended to send this request no more than once every 10 seconds. If the response status isHeartbeatErrorCode == 10, immediately stop (abort) the execution of the Python script of the Robot.
If the response status isHeartbeatErrorCode == 20, perform a proper termination of the Python script of the Robot.After the completion of the Python script of the Robot, perform an HTTP PUT request to the
/api/job/updatescript of the Orchestrator. Pass the GUID of the current Job of the Robot (guid) and the new Job status depending on the result of its completion according to the reference provided above.Then perform an HTTP POST request to the
/api/robot/heartbeatscript of the Orchestrator with the statusStatus = 2 (Status_Ready)and return to step 2 of the framework algorithm.