robocorp-workitems
module robocorp.workitems
Variables
- inputs
- outputs
Functions
Class Input
Container for an input work item.
An input work item can contain arbitrary JSON data in the payload
section, and optionally attached files that are stored in Control Room.
Each step run of a process in Control Room has at least one input work item associated with it, but the step's input queue can have multiple input items in it.
There can only be one input work item reserved at a time. To reserve the next item, the current item needs to be released as either passed or failed.
__init__
Properties
exception
Current work item exception if any.
files
Names of attached files.
id
Current ID for work item.
outputs
Child output work items.
parent_id
Current parent work item ID (output only).
payload
Current JSON payload.
released
Is the current item released.
saved
Is the current item saved.
state
Current release state.
Methods
add_file
Attach a file from the local machine to the work item.
Note: Files are not uploaded until the item is saved.
Args:
path
: Path to attached filename
: Custom name for file in work item
Returns: Resolved path to added file
add_files
Attach files from the local machine to the work item that match the given pattern.
Note: Files are not uploaded until the item is saved.
Args:
pattern
: Glob pattern for attached file paths
Returns: List of added paths
create_output
Create an output work item that is a child of this item.
done
Mark this work item as done, and release it.
email
Parse an email attachment from the work item.
Args:
html
: Parse the HTML content into thehtml
attributeencoding
: Text encoding of the emailignore_errors
: Ignore possible parsing errors from Control Room
Returns: An email container with metadata and content
Raises:
ValueError
: No email attached or content is malformed
fail
Mark this work item as failed, and release it.
Args:
exception_type
: Type of failure (APPLICATION or BUSINESS)code
: Custom error code for the failuremessage
: Human-readable error message
get_file
Download file with given name.
If a path
is not defined, uses the Robot root or current working directory.
Args:
name
: Name of filepath
: Path to created file
Returns: Path to created file
get_files
Download all files attached to this work item that match the given pattern.
If a path
is not defined, uses the Robot root or current working directory.
Args:
pattern
: Glob pattern for file namespath
: Directory to store files in
Returns: List of created file paths
load
Load work item payload and file listing from Control Room.
remove_file
Remove attached file with given name.
Note: Files are not removed from Control Room until the item is saved.
Args:
name
: Name of filemissing_ok
: Do nothing if given file does not exist
remove_files
Remove attached files that match the given pattern.
Note: Files are not removed from Control Room until the item is saved.
Args:
pattern
: Glob pattern for file names
Returns: List of matched names
save
Save the current input work item.
Updates the work item payload and adds/removes all pending files.
Note: Modifying input work items is not recommended, as it will make traceability after execution difficult, and potentially makethe process behave in unexpected ways.
Class Inputs
Inputs represents the input queue of work items.
It can be used to reserve and release items from the queue, and iterate over them.
Properties
current
The current reserved input item.
released
A list of inputs reserved and released during the lifetime of the library.
Methods
reserve
Reserve a new input work item.
There can only be one item reserved at a time.
Returns: Input work item
Raises:
RuntimeError
: An input work item is already reservedworkitems.EmptyQueue: There are no further items in the queue
Class Output
Container for an output work item.
Created output items are added to an output queue, and released to the next step of a process when the current run ends.
Note: An output item always has an input item as a parent, which is used for traceability in a work item's history.
__init__
Properties
files
Names of attached files.
id
Current ID for work item.
parent_id
Current parent work item ID (output only).
payload
Current JSON payload.
saved
Is the current item saved.
Methods
add_file
Attach a file from the local machine to the work item.
Note: Files are not uploaded until the item is saved.
Args:
path
: Path to attached filename
: Custom name for file in work item
Returns: Resolved path to added file
add_files
Attach files from the local machine to the work item that match the given pattern.
Note: Files are not uploaded until the item is saved.
Args:
pattern
: Glob pattern for attached file paths
Returns: List of added paths
load
Load work item payload and file listing from Control Room.
remove_file
Remove attached file with given name.
Note: Files are not removed from Control Room until the item is saved.
Args:
name
: Name of filemissing_ok
: Do nothing if given file does not exist
remove_files
Remove attached files that match the given pattern.
Note: Files are not removed from Control Room until the item is saved.
Args:
pattern
: Glob pattern for file names
Returns: List of matched names
save
Save the current work item.
Updates the work item payload and adds/removes all pending files.
Class Outputs
Outputs represents the output queue of work items.
It can be used to create outputs and inspect the items created during the execution.
Properties
last
The most recently created output work item, or None
.
Methods
create
Create a new output work item, which can have both a JSON payload and attached files.
Creating an output item requires an input to be currently reserved.
Args:
payload
: JSON serializable data (dict, list, scalar, etc.)files
: List of paths to files or glob patternsave
: Immediately save item after creation
Raises:
RuntimeError
: No input work item reserved
Exceptions
ApplicationException
An exception that can be raised to release an input work item with an APPLICATION exception type.
__init__
BusinessException
An exception that can be raised to release an input work item with a BUSINESS exception type.
__init__
EmptyQueue
Raised when trying to load an input item and none available.
Enums
ExceptionType
Failed work item error type.
Values
- BUSINESS = BUSINESS
- APPLICATION = APPLICATION
State
Work item state, after release.
Values
- DONE = COMPLETED
- FAILED = FAILED