saturnin.component.controller¶
Saturnin service controllers.
Constants and variables¶
Functions¶
- saturnin.component.controller.service_thread(service: ServiceInfo, config: Config, ctrl_addr: ZMQAddress, peer_uid: UUID = None)[source]¶
Thread target code to run the service.
- Parameters:
svc_descriptor – Service descriptor.
config (Config) – Service configuration.
ctrl_addr (ZMQAddress) – Address for control ZMQ socket.
peer_uid (UUID) – Peer ID.
service (ServiceInfo) –
Classes¶
- class saturnin.component.controller.ServiceExecConfig(name: str)[source]¶
Bases:
Config
Service executor configuration.
- Parameters:
name (str) – Default conf. section name
- agent: UUIDOption¶
Agent (service) identification
- class saturnin.component.controller.ServiceController(*args, **kwargs)[source]¶
Bases:
TracedMixin
Base service controller.
- __init__(service: ServiceInfo, *, name: str = None, peer_uid: UUID = None, manager: ChannelManager = None)[source]¶
- Parameters:
service (ServiceInfo) – Service to start.
name (str) – Container name.
peer_uid (UUID) – Peer ID,
None
means that newly generated UUID type 1 should be used.manager (ChannelManager) – ChannelManager to be used.
- configure(config: ConfigParser, section: str = None) None [source]¶
Loads and validates service configuration, and ensures that Saturnin facilities required by service are available and properly configured.
- Parameters:
config (ConfigParser) – ConfigParser instance with service configuration.
section (str) – Name of section with service configuration. If not present, uses
ServiceContainer.name
value.
- Return type:
None
- class saturnin.component.controller.DirectController(*args, **kwargs)[source]¶
Bases:
ServiceController
Service controller that starts the service in current thread.
Although ICCP is used to start/stop the service, it’s not possible to perform any ICCP interactions with the service while it’s running.
Important
The service could be stopped only via automatically installed SIGINT handler.
- handle_stop_controller(exc: Exception) None [source]¶
Called when controller should stop its operation due to error condition.
- Parameters:
exc (Exception) – Exception that describes the reason why component should stop.
- Return type:
None
- start(*, timeout: int = 10000) None [source]¶
Start the service.
- Parameters:
timeout (int) – Only for compatibility with ThreadController. The value is ignored.
- Return type:
None
Important
Will not return until service is stopped via SIGINT, or exception is raised.
- Raises:
ServiceError – On error in communication with service.
- Parameters:
timeout (int) –
- Return type:
None
- class saturnin.component.controller.ThreadController(*args, **kwargs)[source]¶
Bases:
ServiceController
Service controller that starts the service in separate thread.
- __init__(service: ServiceDescriptor, *, name: str = None, peer_uid: UUID = None, manager: ChannelManager = None)[source]¶
- Parameters:
service (ServiceDescriptor) – Service to start.
name (str) – Container name.
peer_uid (UUID) – Peer ID,
None
means that newly generated UUID type 1 should be used.manager (ChannelManager) –
- handle_stop_controller(exc: Exception) None [source]¶
Called when controller should stop its operation due to error condition.
- Parameters:
exc (Exception) – Exception that describes the reason why component should stop.
- Return type:
None
- join(timeout=None) None [source]¶
Wait until service stops.
- Parameters:
timeout – Floating point number specifying a timeout for the operation in seconds (or fractions thereof).
- Return type:
None
- start(*, timeout: int = 10000) None [source]¶
Start the service.
- Parameters:
timeout (int) – Timeout (in milliseconds) to wait for service to report it’s ready.
- Raises:
ServiceError – On error in communication with service.
TimeoutError – When timeout expires.
- Return type:
None
- stop(*, timeout: int = 10000) None [source]¶
Stop the service. Does nothing if service is not running.
- Parameters:
timeout (int) – None (infinity), or timeout (in milliseconds) for the operation.
- Raises:
ServiceError – On error in communication with service.
TimeoutError – When service does not stop in time.
- Return type:
None