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) for ServiceGroup: 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:
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:
Return type:

ComponentExecutionState

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:

async run_extra_handler(stage, ctx, pipeline)[source]#
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).

Parameters:
Return type:

None

add_extra_handler(global_extra_handler_type, extra_handler)[source]#

Method for adding a global extra handler to this particular component.

Parameters:
Returns:

None

_get_runtime_info(ctx)[source]#

Method for retrieving runtime info about this component.

Parameters:

ctx (Context) – Current dialog Context.

Return type:

ServiceRuntimeInfo

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.