Executor: Task execution machinery

class invoke.executor.Executor(collection, context=None)

An execution strategy for Task objects.

Subclasses may override various extension points to change, add or remove behavior.

Initialize executor with handles to a task collection & config context.

The collection is used for looking up tasks by name and storing/retrieving state, e.g. how many times a given task has been run this session and so on. It is optional; if not given a blank Context is used.

A copy of the context is passed into any tasks that mark themselves as requiring one for operation.

execute(*tasks, **kwargs)

Execute one or more tasks in sequence.

Parameters:
  • tasks (iterable) –

    An iterable of two-tuples whose first element is a task name and whose second element is a dict suitable for use as **kwargs. E.g.:

    [
        ('task1', {}),
        ('task2', {'arg1': 'val1'}),
        ...
    ]
    

    As a shorthand, a string instead of a two-tuple may be given, implying an empty kwargs dict.

    The string specifies which task from the Executor’s Collection is to be executed. It may contain dotted syntax appropriate for calling namespaced tasks, e.g. subcollection.taskname.

    Thus the above list-of-tuples is roughly equivalent to:

    task1()
    task2(arg1='val1')
    
  • dedupe (bool) – Whether to perform deduplication on the tasks and their pre/post-tasks. See Task deduplication.
Returns:

A dict mapping task objects to their return values. This may include pre- and post-tasks if any were executed.

Previous topic

exceptions: Custom exception subclasses

Next topic

Loader: Loading of task definition files

This Page