Component#
The Component module defines a PipelineComponent
class,
which is a fundamental building block of the framework. A PipelineComponent represents a single
step in a processing pipeline, and is responsible for performing a specific task or set of tasks.
The PipelineComponent class can be a group or a service. It is designed to be reusable and composable, allowing developers to create complex processing pipelines by combining multiple components.
- class PipelineComponent(before_handler=None, after_handler=None, timeout=None, requested_async_flag=None, calculated_async_flag=False, start_condition=None, name=None, path=None)[source]#
Bases:
ABC
This class represents a pipeline component, which is a service or a service group. It contains some fields that they have in common.
- Parameters:
before_handler (Optional[
ExtraHandlerBuilder
]) –BeforeHandler
, associated with this component.after_handler (Optional[
ExtraHandlerBuilder
]) –AfterHandler
, associated with this component.timeout (Optional[float]) – (for asynchronous only!) Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.
requested_async_flag (Optional[bool]) – Requested asynchronous property; if not defined, calculated_async_flag is used instead.
calculated_async_flag (bool) – Whether the component can be asynchronous or not 1) for
Service
: whether its handler is asynchronous or not, 2) forServiceGroup
: whether all its services are asynchronous or not.start_condition (Optional[
StartConditionCheckerFunction
]) – StartConditionCheckerFunction that is invoked before each component execution; component is executed only if it returns True.name (Optional[str]) – Component name (should be unique in single
ServiceGroup
), should not be blank or contain . symbol.path (Optional[str]) – Separated by dots path to component, is universally unique.
- timeout#
Maximum component execution time (in seconds), if it exceeds this time, it is interrupted (for asynchronous only!).
- requested_async_flag#
Requested asynchronous property; if not defined,
requested_async_flag
is used instead.
- calculated_async_flag#
Calculated asynchronous property, whether the component can be asynchronous or not.
- start_condition#
Component start condition that is invoked before each component execution; component is executed only if it returns True.
- name#
Component name (should be unique in single
ServiceGroup
), should not be blank or contain ‘.’ symbol.
- path#
Dot-separated path to component (is universally unique). This attribute is set in
finalize_service_group()
.
- _set_state(ctx, value)[source]#
Method for component runtime state setting, state is preserved in ctx.framework_states dict, in subdict, dedicated to this library.
- Parameters:
value (
ComponentExecutionState
) – State to set.
- Returns:
None
- get_state(ctx, default=None)[source]#
Method for component runtime state getting, state is preserved in ctx.framework_states dict, in subdict, dedicated to this library.
- Parameters:
default (
Optional
[ComponentExecutionState
]) – Default to return if no record found (usually it’sNOT_RUN
).
- Return type:
- Returns:
ComponentExecutionState
of this service or default if not found.
- property asynchronous: bool#
Property, that indicates, whether this component is synchronous or asynchronous. It is calculated according to the following rules:
- If component can be asynchronous and
requested_async_flag
is set, it returnsrequested_async_flag
. - If component can be asynchronous and
requested_async_flag
isn’t set, it returns True. - If component can’t be asynchronous and
requested_async_flag
is False or not set, it returns False. - If component can’t be asynchronous and
requested_async_flag
is True, an Exception is thrown in constructor.
- abstract async _run(ctx, pipeline)[source]#
A method for running pipeline component, it is overridden in all its children. This method is run after the component’s timeout is set (if needed).
- add_extra_handler(global_extra_handler_type, extra_handler)[source]#
Method for adding a global extra handler to this particular component.
- Parameters:
global_extra_handler_type (
GlobalExtraHandlerType
) – A type of extra handler to add.extra_handler (
ExtraHandlerFunction
) – AGlobalExtraHandlerType
to add to the component as an extra handler.
- Returns:
None
- _get_runtime_info(ctx)[source]#
Method for retrieving runtime info about this component.
- Parameters:
- Return type:
- Returns:
ServiceRuntimeInfo
object where all not set fields are replaced with [None].
- property info_dict: dict#
Property for retrieving info dictionary about this component. All not set fields there are replaced with [None].
- Returns:
Info dict, containing most important component public fields as well as its type.