saturnin.component.controller

Saturnin service controllers.

Constants and variables

saturnin.component.controller.SVC_CTRL: Final[str] = 'iccp'

Service control channel name

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

property logging_id: str

Returns qualified class name and agent name.

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

stop_signal_handler(signum: int, param) None[source]

The signal.signal SIGINT handler that sends ICCP STOP message to the service.

Parameters:

signum (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:
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

is_running() bool[source]

Returns True if service is running.

Return type:

bool

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:
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:
Return type:

None

terminate() None[source]

Terminate the service.

Terminate should be called ONLY when call to stop() (with sensible timeout) fails. Does nothing when service is not running.

Raises:

Error – When service termination fails.

Return type:

None