Metadata-Version: 2.4
Name: rpa-bot-sdk-performer
Version: 1.6.0
Summary: Orchestrator bot-side Performer role: REFramework-style state machine, QueueManager, TransactionItem, ExcelReporter.
Author: Kasun Perera
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: rpa-bot-sdk-core<2.0.0,>=1.8.0
Requires-Dist: openpyxl

# rpa-bot-sdk-performer

The Performer role's orchestration layer: `QueueManager`, `TransactionItem`,
the `FrameworkState` state machine (`InitState` -> `GetTransactionState` ->
`ProcessState` -> `EndTransactionState` -> `EndProcessState`), and
`ExcelReporter`.

Depends on [`rpa-bot-sdk-core`](../core/README.md) for the server client and
pause/stop controller — installing this package pulls that one in
automatically. A Dispatcher project never needs this package at all; install
[`rpa-bot-sdk-dispatcher`](../dispatcher/README.md) instead.

## In a Performer project's `requirements.txt`

```
rpa-bot-sdk-core==1.8.0
rpa-bot-sdk-performer==1.6.0
```

## A Secure Cloud Performer

Build the client yourself and hand it over, so the items it fetches are
decrypted and every write it makes (a retry, a requeue, `update_item_data`)
is encrypted again before it leaves the machine:

```python
from rpa_bot_sdk_core import SecureDbClient
from rpa_bot_sdk_performer import QueueManager

client = SecureDbClient(base_url=url, api_key=key,
                        phi_key_path="data/phi.key", secure_fields="*")
queue = QueueManager("", config, sub_process_name="Performer", client=client)
```

`queue.client` is the registered client. Reuse it for any other server call
of the run, so the call carries this run's token.

## Holding an item back: `queue.requeue()` (1.4.0)

```python
later = (datetime.now(timezone.utc) + timedelta(minutes=30)).isoformat()
queue.requeue(item, postpone_until=later)
```

The item this run holds goes back to New and is not dispatched before
`postpone_until`. It is the same queue row: its Unique ID, data and retry
count are kept, and the wait is not counted as a failed attempt -- use it
while a person answers an action the item waits on (docs/HUMAN_ACTIONS.md).
A refusal raises `RuntimeError`.

The row's data is not sent. To keep something for the next pass, such as
the `action_id` the item waits on, store it first:

```python
item.data["_json_data"]["action_id"] = action_id
queue.update_item_data(item)
queue.requeue(item, postpone_until=later)
```

Before 1.4.0 it added the item again under the same Unique ID, which the
Orchestrator refuses as a duplicate, so the item was lost. It needs
Orchestrator v20.15.0, which answers `postpone_transaction`.

## Retries, STOP and the run's outcome (1.5.0)

- A system exception is retried with one atomic call
  (`update_transaction_status` with `increment_retry`): the Orchestrator
  marks the attempt Retry and queues the next one in the same transaction,
  keeping the Unique ID, or fails the item once `MaxRetries` are used up.
  Before, a second `add_queue_item` call added `X_R1`, and when it failed the
  item was lost.
- `sys_exception` in the run's summary counts only items whose retries ran
  out; `retried` counts the retried attempts. An item that fails once and
  then succeeds no longer fails the run. Every attempt has a row in
  Output.xlsx.
- `ProcessState` never stops between an item's steps and its record. A STOP
  inside the steps (a checkpoint or `safe_*` call) puts the item back in the
  queue with `requeue()`, its retry count unchanged, and ends the run.
  Session objects (`_browser`, ...) come back to the run's config even when an
  item fails, so INIT can close them.
- `ReferenceFilter` narrows the enabled tenants and never widens them, and a
  Tenant List with no tenant in scope means no item -- it used to mean every
  tenant.

## A refused update is reported (1.6.0)

`update_queue_row()` and `update_item_data()` return the Orchestrator's reply
and log a warning -- without the server's text -- when the update was refused
or never arrived, so an item that stays InProgress on the Orchestrator shows
in the bot's log. Output.xlsx is written to a temporary file and moved into
place: a crash or a full disk leaves the previous report, never half of one.
1.6.0 needs `rpa-bot-sdk-core` 1.8.0.

Pin both exactly. `rpa-bot-sdk-performer`'s own dependency on core is a
range (`>=1.0.0,<2.0.0`), which is fine for the *library* — a bot project's
own `requirements.txt` is what needs to be exact, so every machine installs
the same bytes.
