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 returns True.

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:
get_state(ctx, default=None)[source]#

Method for component runtime state getting, state is preserved in Context.framework_data.

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_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 a ServiceGroup have the same computed_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).

Parameters:
Return type:

None

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.

Parameters:
Return type:

Optional[Awaitable]

Returns:

None if the service is synchronous; an Awaitable otherwise.

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.