Service#
The Service module contains the Service
class which represents a single task.
Pipeline consists of services and service groups. Service is an atomic part of a pipeline.
- class Service(**data)[source]#
Bases:
PipelineComponent
This class represents a service.
- handler: Union[BaseProcessing, Callable[[Context], None]]#
Function that represents this service.
- before_handler: BeforeHandler#
BeforeHandler
, associated with this component.
- after_handler: AfterHandler#
AfterHandler
, associated with this component.
- timeout: Optional[float]#
Maximum component execution time (in seconds), if it exceeds this time, it is interrupted.
- concurrent: bool#
Optional flag that indicates whether this component should be executed concurrently with adjacent concurrent components.
- start_condition: AnyCondition#
AnyCondition
that is invoked before each component execution; component is executed only if it returnsTrue
.
- name: Optional[str]#
Name of the component. Defaults to
computed_name
potentially modified byrename_component_incrementing()
.See
validate_name()
for rules.
- path: Optional[str]#
Separated by dots path to component, is universally unique.
- classmethod handler_validator(data)[source]#
Add support for initializing from a Callable or BaseProcessing.
- async call(ctx)[source]#
A placeholder method which the user can redefine in their own derivative of
Service
. This allows direct access to theself
object and all its fields.- Parameters:
ctx (
Context
) – Current dialog context.- Return type:
None
- async run_component(ctx)[source]#
Method for running this service.
- Parameters:
ctx (
Context
) – Current dialog context.- Return type:
None
- Returns:
None
- property computed_name: str#
Return name of the handler or name of this class if handler is empty.
- to_service(before_handler=None, after_handler=None, timeout=None, concurrent=False, start_condition=True, name=None)[source]#
Return a function decorator that returns a
Service
with the given parameters.
- ServiceInitTypes#
Types that
Service
can be validated from.alias of
Union
[Service
, typing.Annotated[dict, ‘dict following the Service data model’],Callable
[Callable
],BaseProcessing
[BaseProcessing
]]