Extra Handler#

The Extra Handler module contains additional functionality that extends the capabilities of the system beyond the core functionality. Extra handlers is an input converting addition to PipelineComponent. For example, it is used to grep statistics from components, timing, logging, etc.

class _ComponentExtraHandler(functions, stage=ExtraHandlerType.UNDEFINED, timeout=None, asynchronous=None)[source]#

Bases: object

Class, representing an extra pipeline component handler. A component extra handler is a set of functions, attached to pipeline component (before or after it). Extra handlers should execute supportive tasks (like time or resources measurement, minor data transformations). Extra handlers should NOT edit context or pipeline, use services for that purpose instead.

Parameters:
  • functions (ExtraHandlerBuilder) – An ExtraHandlerBuilder object, an _ComponentExtraHandler instance, a dict or a list of ExtraHandlerFunction.

  • stage (ExtraHandlerType) – An ExtraHandlerType, specifying whether this handler will be executed before or after pipeline component.

  • timeout (Optional[float]) – (for asynchronous only!) Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.

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

property asynchronous: bool#

Property, that indicates, whether this component extra handler is synchronous or asynchronous. It is calculated according to the following rules:

  • If component can be asynchronous and requested_async_flag is set, it returns requested_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.
async _run_function(func, ctx, pipeline, component_info)[source]#
async _run(ctx, pipeline, component_info)[source]#

Method for executing one of the wrapper functions (before or after). If the function is not set, nothing happens.

Parameters:
  • stage – current WrapperStage (before or after).

  • ctx (Context) – current dialog context.

  • pipeline (Pipeline) – the current pipeline.

  • component_info (ServiceRuntimeInfo) – associated component’s info dictionary.

Returns:

None

property info_dict: dict#

Property for retrieving info dictionary about this wrapper.

Returns:

Info dict, containing its fields as well as its type. All not set fields there are replaced with None.

class BeforeHandler(functions, timeout=None, asynchronous=None)[source]#

Bases: _ComponentExtraHandler

A handler for extra functions that are executed before the component’s main function.

Parameters:
  • functions (ExtraHandlerBuilder) – A callable or a list of callables that will be executed before the component’s main function.

  • timeout (Optional[int]) – Optional timeout for the execution of the extra functions, in seconds.

  • asynchronous (Optional[bool]) – Optional flag that indicates whether the extra functions should be executed asynchronously. The default value of the flag is True if all the functions in this handler are asynchronous.

class AfterHandler(functions, timeout=None, asynchronous=None)[source]#

Bases: _ComponentExtraHandler

A handler for extra functions that are executed after the component’s main function.

Parameters:
  • functions (ExtraHandlerBuilder) – A callable or a list of callables that will be executed after the component’s main function.

  • timeout (Optional[int]) – Optional timeout for the execution of the extra functions, in seconds.

  • asynchronous (Optional[bool]) – Optional flag that indicates whether the extra functions should be executed asynchronously. The default value of the flag is True if all the functions in this handler are asynchronous.