robocorp-tasks
module robocorp.tasks
Robocorp tasks helps in creating entry points for your automation project.
To use:
Mark entry points with:
Running options:
Runs all the tasks in a .py file:
python -m robocorp.tasks run <path_to_file>
Run all the tasks in files named task.py:
python -m robocorp.tasks run <directory>
Run only tasks with a given name:
python -m robocorp.tasks run <directory or file> -t <task_name>
Note: Using the cli.main(args)
is possible to run tasks programmatically, but clients using this approach MUST make sure that any code which must be automatically logged is not imported prior the the cli.main
call.
Functions
task
Decorator for tasks (entry points) which can be executed by robocorp.tasks
.
i.e.:
If a file such as tasks.py has the contents below:
It's also possible to pass options to the task decorator that can then be introspected by task.options
:
It'll be executable by robocorp tasks as:
python -m robocorp.tasks run tasks.py -t enter_user
Args:
func
: A function which is a task torobocorp.tasks
.**kwargs
: Options to be introspected bytask.options
.
setup
Run code before any tasks start, or before each separate task.
Receives as an argument the task or tasks that will be run.
Can be used as a decorator without arguments:
Alternatively, can be called with a scope
argument to decide when the fixture is run:
By default, runs setups in task
scope.
The setup
fixture also allows running code after the execution, if it yield
s the execution to the task(s):
Note: If fixtures are defined in another file, they need to be imported in the main tasks file to be taken into use
teardown
Run code after tasks have been run, or after each separate task.
Receives as an argument the task or tasks that were executed, which contain (among other things) the resulting status and possible error message.
Can be used as a decorator without arguments:
Alternatively, can be called with a scope
argument to decide when the fixture is run:
By default, runs teardowns in task
scope.
Note: If fixtures are defined in another file, they need to be imported in the main tasks file to be taken into use
session_cache
Provides decorator which caches return and clears automatically when all tasks have been run.
A decorator which automatically cache the result of the given function and will return it on any new invocation until robocorp-tasks finishes running all tasks.
The function may be either a generator with a single yield (so, the first yielded value will be returned and when the cache is released the generator will be resumed) or a function returning some value.
Args:
func
: wrapped function.
task_cache
Provides decorator which caches return and clears it automatically when the current task has been run.
A decorator which automatically cache the result of the given function and will return it on any new invocation until robocorp-tasks finishes running the current task.
The function may be either a generator with a single yield (so, the first yielded value will be returned and when the cache is released the generator will be resumed) or a function returning some value.
Args:
func
: wrapped function.
get_output_dir
Provide the output directory being used for the run or None if there's no output dir configured.
get_current_task
Provides the task which is being currently run or None if not currently running a task.
Class ITask
Properties
failed
Returns true if the task failed. (in which case usually exc_info is not None).
input_schema
The input schema from the function signature.
Example:
lineno
The line where the task is declared.
managed_params_schema
The schema for the managed parameters.
Example:
name
The name of the task.
output_schema
The output schema based on the function signature.
Example:
Methods
run
Runs the task and returns its result.
Enums
Status
Task state
Values
- NOT_RUN = NOT_RUN
- PASS = PASS
- FAIL = FAIL