saturnin.component.micro

Saturnin base module for implementation of Firebird Butler Microservices.

Constants and variables

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

Service control channel name

Classes

class saturnin.component.micro.MicroService(*args, **kwargs)[source]

Bases: Component, TracedMixin

Saturnin Component for Firebird Burler Microservices.

__init__(zmq_context: Context, descriptor: ServiceDescriptor, *, peer_uid: UUID = None)[source]
Parameters:
  • zmq_context (Context) – ZeroMQ Context.

  • descriptor (ServiceDescriptor) – Service descriptor.

  • peer_uid (UUID) – Peer ID, None means that newly generated UUID type 1 should be used.

aquire_resources() None[source]

Aquire resources required by component (open files, connect to other services etc.).

Must raise an exception when resource aquisition fails.

Return type:

None

bind_endpoints() None[source]

Bind endpoints used by component.

Return type:

None

get_timeout() int[source]

Returns timeout to next scheduled action.

Return type:

int

handle_config_request(config: ConfigProto) None[source]

ICCP event handler. Called when controller requested reconfiguration.

Must raise an exception if configuration fails for any reason.

By default, the component does not support run-time configuration, so it raises NotImplementedError.

Parameters:

config (ConfigProto) – New configuration provided by controller.

Return type:

None

handle_stop_component(exc: Exception = None) None[source]

ICCP event handler. Called when commponent should stop its operation. It stops the component by setting the stop event.

Parameters:

exc (Exception) – Exception that describes the reason why component should stop. If not provided, the component should stop on controller’s request.

Return type:

None

initialize(config: ComponentConfig) None[source]

Verify configuration and assemble component structural parts.

Parameters:

config (ComponentConfig) – Service configuration.

Return type:

None

release_resources() None[source]

Release resources aquired by component (close files, disconnect from other services etc.)

Return type:

None

run() None[source]

Component execution (main loop).

Return type:

None

run_scheduled() None[source]

Run scheduled actions.

Return type:

None

schedule(action: Callable, after: int) None[source]

Schedule action to be executed after specified time.

Action is executed in run() main I/O loop not sooner than after specified number of milliseconds from time when schedule() is called. However, the actual delay could be longer than specified (depends on time spent in message handlers and other factors).

Parameters:
  • action (Callable) – Callable (without arguments) to be executed. Use functools.partial if callable requires arguments.

  • after (int) – Delay in milliseconds.

Return type:

None

start_activities() None[source]

Start normal component activities.

Must raise an exception when start fails.

Return type:

None

stop_activities() None[source]

Stop component activities.

Return type:

None

warm_up(ctrl_addr: ZMQAddress | None) None[source]

Initializes the ChannelManager and connects component to control channel.

Parameters:

ctrl_addr (ZMQAddress | None) –

Return type:

None

descriptor: ServiceDescriptor

Service desriptor.

details: Exception | List[str]

Service execution outcome details

endpoints: Dict[str, List[ZMQAddress]]

Dictionary with endpoints to which the component binds. Key is channel name, value is list of ZMQAddress instances. Initially empty.

property logging_id: str

Returns _logging_id_ or <agent_name>[<peer.uid.hex>]

mngr: ChannelManager

ChannelManager instance.

outcome: Outcome

Service execution outcome

peer: PeerDescriptor

Peer descriptor for this component.

state: State

Service internal state

stop: Event

Event to stop the component