Executor: Task execution machinery

class invoke.executor.Executor(collection, context)

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.

The context is passed into any tasks that mark themselves as requiring one for operation.

execute(name, kwargs=None, dedupe=True)

Execute a named task, honoring pre- or post-tasks and so forth.

Parameters:
  • name – A string naming which task from the Executor’s Collection is to be executed. May contain dotted syntax appropriate for calling namespaced tasks, e.g. subcollection.taskname.
  • kwargs

    A keyword argument dict expanded when calling the requested task. E.g.:

    executor.execute('mytask', {'myarg': 'foo'})
    

    is (roughly) equivalent to:

    mytask(myarg='foo')
    
  • dedupe – Ensures any given task within self.collection is only run once per session. Set to False to disable this behavior.
Returns:

The return value of the named task – regardless of whether pre- or post-tasks are executed.

Previous topic

exceptions: Custom exception subclasses

Next topic

Loader: Loading of task definition files

This Page