# Deploying the Framework on the Target Account

* Install Python for all users, check "Add python.exe to PATH" in Customize Installation:
  * install python for all users
  * Associate files with Python (request the "py" launcher)
  * Create shortcuts for installed applications
  * Add Python to environment variables
  * Precompile standard library
* Create a task in the Windows Task Scheduler with any name General:

  * "Run only for users logged on"

  Triggers:

  * "At log on" --> "User" (specify)
  * "On remote connection" --> "Connection from a remote computer" --> "User" (specify)

  Actions:

  * "Start a program"
  * "Program/script" --> Full path to SherpaPython.exe
  * "Start in" --> Path to the folder where SherpaPython.exe is located, without quotes, for example: D:\Sherpa\_RPA\PythonSherpa-framework\\
* Run SherpaPython.exe manually once
* The framework logs will be located at C:\Users\User\AppData\Roaming\Sherpa RPA Python
* The settings file settings.txt will be located at C:\Users\User\AppData\Roaming\Sherpa RPA Python

Contents of settings.txt

* << Enter robot guid >> - replace with the robot's GUID
* << Enter robot host >> - enter the host or IP of the orchestrator along with the protocol, for example <https://orchestrator2.sherparpa.ru>
* << Enter robot logoff status >> - one digit (0 - no automatic logoff after work is completed, 1 - automatic logoff after work is completed, if the third line is absent, the value 1 is assumed)

***

```
                    RobotsOrcFramework
```

***

```
Handling soft stop inside the python robot

import signal
import time
import sys

class TestProcess1():
    stop = False
    def __init__(self):
    # Intercept soft stop signal from the framework
        signal.signal(signal.SIGBREAK, self.stop_process)

    # Handle the signal by toggling the flag
    def stop_process(self, signal, frame):
        self.stop = True 

    def robot_work(self):
        for elem in range(10):
            time.sleep(1)
            # If the flag is in the desired position, terminate the program
            if self.stop:
	    sys.exit()

test = TestProcess1()
test.robot_work()
```

***

```
Get and process arguments from the framework inside the python robot

# process command line arguments
def process_cmd_arguments(argv):
    process_version_guid = argv[0]
    job_guid = argv[1]
    settings_path = argv[3]

process_cmd_arguments(sys.argv[1].split("|"))
```

***

```
Get host and GUID of the robot inside the python robot

# get settings
def get_settings():
    with open(settings_path, "r", encoding="utf-8") as file:
        settings = file.read()
    settings = [elem.replace("\n", "") for elem in settings.split("\n")]

    return settings[0], settings[1]

robot_GUID, host = get_settings()
```

***

```
Path to python scripts of robots

In the process version name in the orchestrator, specify the path to the python script,
relative to the framework file (RobotsOrcFramework.py)

Format
folder1\folder2\script name without extension
```

***

```
                    Using TaskOrchestratorAPI
```

***

```
from TaskOrcAPI import TaskOrchestratorAPI # OrchestratorAPI folder
TOA = TaskOrchestratorAPI(robot_guid, host, headers)
```

***

```
Adding a task to the queue

param_task can be omitted, defaults to {"":""}
name can be omitted, defaults to "NewTask"

queue_GUID = "f96b549d-bc58-48b9-ba78-463692c7680b"
param_task = {"param1": "1", "param2": "2", "param3": "3"}
name = 'New Task'

result = TOA.add_task(queue_GUID)

result['guid'] # d5fc7d6e-b609-4aaa-be35-e51fdacb5b5d
```

***

```
Getting a task from the queue

status can be omitted, defaults to 0

queue_GUID = "f96b549d-bc58-48b9-ba78-463692c7680b"
status = 1

result = TOA.get_task(queue_GUID, status)
result_dict = json.loads(result.text)

result                       # <Response [200]> Request code

result_dict['id']            # 1171
result_dict['guid']          # d5fc7d6e-b609-4aaa-be35-e51fdacb5b5d
result_dict['name']          # NewTask
result_dict['status']        # 4
result_dict['created']       # 2022-10-28 06:19:19
result_dict['updated']       # 2022-10-28 09:45:45
result_dict['comment']       # comment
result_dict['priority']      # 1
result_dict['deadline']      # 2022-10-28 06:19:19
result_dict['postponed']     # 2022-10-28 09:45:45
result_dict['parameters']    # {"param": "value"}
result_dict['description']   # None
```

***

```
Updating the status of the previously received task

Task status reference
STATUS_NEW              = 0;  # New task
STATUS_IN_PROGRESS      = 1;  # Task in progress
STATUS_SUCCESS          = 2;  # Task successfully completed
STATUS_FAILED           = 3;  # Task failed with Application Exception
STATUS_FAILED_BUSINESS  = 4;  # Task failed with Business Exception
STATUS_POSTPONED        = 5;  # Task postponed until specified time
STATUS_ABANDONED        = 6;  # Task abandoned (not processed in time)

status can be omitted, defaults to 0    

task_GUID = '4e9cb924-681a-4d1d-9420-e1dac677f3fa'
status = 5

result = TOA.update_task_status(task_GUID, status)
result # <Response [200]> Request code
```

***

```
Getting the resource (asset)

asset_GUID = "d042c0cf-4862-48e7-8d10-caf892ceec3f"

result = TOA.get_asset(asset_GUID)

result['id']                # 1171
result['guid']              # d5fc7d6e-b609-4aaa-be35-e51fdacb5b5d
result['name']              # Resource
result['text']              # 4
result['type']              # 1
result['created']           # 2022-10-28 06:19:19
result['updated']           # 2022-10-28 06:19:19
result['robot_id']          # None
result['password']          # 2022-10-28 06:19:19
result['is_deleted']        # 0
result['account_id']        # 27
result['robot_type']        # 3
result['description']       # ''
result['robot_group_id']    # None
```

***

```
Updating the resource

name can be omitted, defaults to NewName
if the resource is credentials, specify password, then text = username, otherwise do not specify

asset_GUID = "d042c0cf-4862-48e7-8d10-caf892ceec3f"
text = 'New resource'
name = 'Resource'
password = '777'

result = TOA.asset_update(asset_GUID, text, name, password)
result # <Response [200]> Request code
```

***

```
Adding a new log entry

Allowed values for Level: 'Info', 'Critical', 'Error', 'Warning', 'Debug'

level can be omitted, defaults to 'Info'
message can be omitted, defaults to ''

robot_guid = sys.argv[1]
process_version_guid = 'f7952815-a238-4870-b678-943b0119d0f4'
job_guid = '922d3cc6-99ec-44c2-b0a0-62114c9d2908'
level, message = 'Info', 'message'

result = TOA.add_new_log_entry(
    robot_guid, process_version_guid, job_guid
)
result_dict = json.loads(result.text)

result                  # <Response [200]> Request code
result_dict['guid']     # d5fc7d6e-b609-4aaa-be35-e51fdacb5b5d
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sherparpa.ru/en/sherpa-rpa/sherpa-orchestrator/python-sherpa-framework/razvertyvanie-freimvorka-na-celevoi-uchetnoi-zapisi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
