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]#
(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.
- start_condition: StartConditionCheckerFunction#
StartConditionCheckerFunction
that is invoked before each component execution; component is executed only if it returnsTrue
.
- name: Optional[str]#
Component name (should be unique in a single
ServiceGroup
), should not be blank or contain the.
character.
- path: Optional[str]#
Separated by dots path to component, is universally unique.
- _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, default=None)[source]#
Method for component runtime state getting, state is preserved in
Context.framework_data
.- 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_component(ctx, pipeline)[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 aServiceGroup
have the samecomputed_name
an incrementing number is appended to the name.
- async _run(ctx, pipeline)[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, pipeline)[source]#
A method for calling pipeline components. It sets up timeout if this component is asynchronous and executes it using
_run()
method.
- 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.