Service Group#

The Service Group module contains the ServiceGroup class, which is used to represent a group of related services.

This class provides a way to organize and manage multiple services as a single unit, allowing for easier management and organization of the services within the pipeline.

ServiceGroup serves the important function of grouping services to work together in parallel.

class ServiceGroup(**data)[source]#

Bases: PipelineComponent

A service group class.

Service group can be synchronous or asynchronous. Components in synchronous groups are executed consequently (no matter is they are synchronous or asynchronous). Components in asynchronous groups are executed simultaneously. Group can be asynchronous only if all components in it are asynchronous.

components: List[Union[Service, ServiceGroup]]#

A ServiceGroup object, that will be added to the group.

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.

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.

classmethod components_validator(data)[source]#

Add support for initializing from a Callable, List and PipelineComponent (such as Service) Casts components to list if it’s not already.

async run_component(ctx, pipeline)[source]#

Method for running this service group. Catches runtime exceptions and logs them. It doesn’t include extra handlers execution, start condition checking or error handling - pure execution only. Executes components inside the group based on its asynchronous property. Collects information about their execution state - group is finished successfully only if all components in it finished successfully.

Parameters:
  • ctx (Context) – Current dialog context.

  • pipeline (Pipeline) – The current pipeline.

Return type:

Optional[ComponentExecutionState]

log_optimization_warnings()[source]#

Method for logging service group optimization warnings for all this groups inner components. (NOT this group itself!). Warnings are basically messages, that indicate service group inefficiency or explicitly defined parameters mismatch. These are cases for warnings issuing:

  • Service can be asynchronous, however is marked synchronous explicitly.

  • Service is not asynchronous, however has a timeout defined.

  • Group is not marked synchronous explicitly and contains both synchronous and asynchronous components.

Returns:

None

add_extra_handler(global_extra_handler_type, extra_handler, condition=<function ServiceGroup.<lambda>>)[source]#

Method for adding a global extra handler to this group. Adds extra handler to itself and propagates it to all inner components. Uses a special condition function to determine whether to add extra handler to any particular inner component. Condition checks components path to be in whitelist (if defined) and not to be in blacklist (if defined).

Parameters:
  • global_extra_handler_type (GlobalExtraHandlerType) – A type of extra handler to add.

  • extra_handler (ExtraHandlerFunction) – A ExtraHandlerFunction to add as an extra handler.

  • condition (Callable[[str], bool]) – A condition function.

Returns:

None

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.

property info_dict: dict#

See Component.info_dict property. Adds services key to base info dictionary.

ServiceGroupInitTypes#

Types that ServiceGroup can be validated from.

alias of Union[ServiceGroup, List[Union[Actor, Service, typing.Annotated[dict, ‘dict following the Service data model’], Callable[Callable], ServiceGroupInitTypes]][List[Union[Actor, Service, typing.Annotated[dict, ‘dict following the Service data model’], Callable[Callable], ServiceGroupInitTypes]]], Union[Actor, Service, typing.Annotated[dict, ‘dict following the Service data model’], Callable[Callable], ServiceGroupInitTypes][Union[Actor, Service, typing.Annotated[dict, ‘dict following the Service data model’], Callable[Callable], ServiceGroupInitTypes]], typing.Annotated[dict, ‘dict following the ServiceGroup data model’]]