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. The ServiceGroup serves the important function of grouping services to work together in parallel.

class ServiceGroup(components, before_handler=None, after_handler=None, timeout=None, asynchronous=None, start_condition=None, name=None)[source]#

Bases: PipelineComponent

A service group class. Service group can be included into pipeline as an object or a pipeline component list. 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.

Parameters:
  • components (ServiceGroupBuilder) – A ServiceGroupBuilder object, that will be added to the group.

  • before_handler (Optional[ExtraHandlerBuilder]) – List of ExtraHandlerBuilder to add to the group.

  • after_handler (Optional[ExtraHandlerBuilder]) – List of ExtraHandlerBuilder to add to the group.

  • timeout (Optional[float]) – Timeout to add to the group.

  • asynchronous (Optional[bool]) – Requested asynchronous property.

  • start_condition (Optional[Callable[[Context, Pipeline], bool]]) – StartConditionCheckerFunction that is invoked before each group execution; group is executed only if it returns True.

  • name (Optional[str]) – Requested group name.

async _run_services_group(ctx, pipeline)[source]#

Method for running this service group. It doesn’t include wrappers 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:

None

async _run(ctx, pipeline)[source]#

Method for handling this group execution. Executes before and after execution wrappers, checks start condition and catches runtime exceptions.

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

  • pipeline (Pipeline) – The current pipeline.

Return type:

None

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 wrapper to this group. Adds wrapper to itself and propagates it to all inner components. Uses a special condition function to determine whether to add wrapper to any particular inner component or not. 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 wrapper to add.

  • extra_handler (ExtraHandlerFunction) – A WrapperFunction to add as a wrapper.

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

Returns:

None

property info_dict: dict#

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

static _create_components(services)[source]#

Utility method, used to create inner components, judging by their nature. Services are created from services and dictionaries. ServiceGroups are created from service groups and lists.

Parameters:

services (ServiceGroupBuilder) – ServiceGroupBuilder object (a ServiceGroup instance or a list).

Return type:

List[Union[Service, ServiceGroup]]

Returns:

List of services and service groups.