Component#
The Component module defines a PipelineComponent
class.
This is a base class for pipeline processing and is responsible for performing a specific task.
- class PipelineComponent(**data)[source]#
Bases:
ABC
,BaseModel
Base class for a single task processed by
Pipeline
.- before_handler: BeforeHandler#
BeforeHandler
, associated with this component.
- after_handler: AfterHandler#
AfterHandler
, associated with this component.
- timeout: Optional[float]#
Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.
- concurrent: bool#
Optional flag that indicates whether this component should be executed concurrently with adjacent concurrent components.
- start_condition: AnyCondition#
AnyCondition
that is invoked before each component execution; component is executed only if it returnsTrue
.
- name: Optional[str]#
Name of the component. Defaults to
computed_name
potentially modified byrename_component_incrementing()
.See
validate_name()
for rules.
- path: Optional[str]#
Separated by dots path to component, is universally unique.
- classmethod validate_name(name)[source]#
Validate this component’s name:
Name cannot be empty or contain “.” or “#”.
- Raises:
ValueError – If name failed validation.
- _set_state(ctx, value)[source]#
Method for component runtime state setting, state is preserved in
Context.framework_data
.- Parameters:
value (
ComponentExecutionState
) – State to set.
- get_state(ctx)[source]#
Method for component runtime state getting, state is preserved in
Context.framework_data
.- Parameters:
- Return type:
- Returns:
ComponentExecutionState
of this service.
- abstract async run_component(ctx)[source]#
Run this component.
- Parameters:
- Return type:
Optional
[ComponentExecutionState
]
- property computed_name: str#
Default name that is used if
name
is not defined.In case two components in a
ServiceGroup
have the samecomputed_name
an incrementing number is appended to the name.
- async _run(ctx)[source]#
A method for running a pipeline component. Executes extra handlers before and after execution, launches
run_component()
method. This method is run after the component’s timeout is set (if needed).
- async __call__(ctx)[source]#
A method for calling pipeline components. It sets up timeout and executes it using
_run()
method.
- add_extra_handler(extra_handler_type, extra_handler)[source]#
Add extra handler to this component.
- Parameters:
extra_handler_type (
ExtraHandlerType
) – A type of extra handler to add (before or after).extra_handler (
Union
[Callable
[[Context
],Any
],Callable
[[Context
,ExtraHandlerRuntimeInfo
],Any
]]) – Function to add to the component as an extra handler.