Task¶
-
class
spype.core.task.
PypeInput
[source]¶ A singleton Task that is used, explicitly or implicitly, to begin each pype.
-
class
spype.core.task.
Task
[source]¶ An abstract class whose subclasses encapsulate a unit of work.
-
get_option
(option)[source]¶ Returns an option defined in self or defer to Task MRO.
Parameters: option ( str
) – A supported Spype option. See spype.options.Return type: Any
-
run
(*args, _fixtures=None, _callbacks=None, _predicate=None, **kwargs)[source]¶ Call the task’s __call__ and handle spype magic in the background.
- Run essentially performs the following steps:
- Try to bind args and kwawrgs to the task signature
- If bind raises, look for missing arguments in _fixtures
- Rebind args and kwargs to signature with new args if needed
- Run on_start callback, if defined
- Run task call method (or function)
- Run on_failure callback if defined and an exception was raised
- Run on_success callback if defined and no exception was raised
- Run on_finish callback, if defined
- Return output of call method, or output of any callback if any non-None values were returned.
Parameters: - _fixtures (
Optional
[Mapping
[str
,Any
]]) – A dict of fixtures. Keys are parameters that might be used by callbacks and values are the values to substitute. - _callbacks (
Optional
[Mapping
[str
,Union
[Callable
,Sequence
[Callable
]]]]) – A dict of callbacks. Keys must be supported callback names (str) and values must be callables. - _predicate (
Union
[Callable
[…,bool
],Sequence
[Callable
[…,bool
]],None
]) – A single function, or sequence of functions, that return a bool. Standard fixtures can be used, just like in callbacks.
-
validate_callback
(callback)[source]¶ Raise TypeError if callback is not a valid callback for this task.
Parameters: callback ( Callable
) – Any callableReturn type: None
-
-
spype.core.task.
task
(func=None, *, on_start=None, on_failure=None, on_success=None, on_finish=None, predicate=None, **kwargs)[source]¶ Decorator for registering a callable as a tasks.
This essentially adds the Task class attributes to a function and returns the function. This means the function will behave as before, but will have the Task class attributes attached. This approach is needed so that the tasks are pickable, else returning Task instances would work.
Parameters: - func (
Optional
[Callable
]) – A callable to use as a task - on_start (
Union
[Callable
,Sequence
[Callable
],None
]) – Callable which is called before running task - on_failure (
Union
[Callable
,Sequence
[Callable
],None
]) – Callable which will be called when a task fails - on_success (
Union
[Callable
,Sequence
[Callable
],None
]) – Callable that gets called when a task succeeds - on_finish (
Union
[Callable
,Sequence
[Callable
],None
]) – Callable that gets called whenever a task finishes
Returns: An instance of Task
Return type: - func (