Skip to content

base_service

messageflux.base_service

BaseService

BaseService(*, name=None, should_stop_on_signal=True)

this class is the base class for all services

Parameters:

Name Type Description Default
name Optional[str]

the name of this service. if None, the name of the type will be used

None
should_stop_on_signal bool

if True, the service will try to register SIGTERM and SIGINT on stop method.

True

is_alive property

is_alive

this property is True, if the service is running.

name property

name

the name of the service

service_state property

service_state

this is the current service state

state_changed_event property

state_changed_event

this is an Event, that can be used to register on server state changes

start

start()

starts the service, and blocks until 'stop' is called

stop

stop()

stops the service (sets the cancellation token, so the service will stop gracefully)

ServiceState

Bases: Enum

the states of the service: INITIALIZING->(start)->STARTING->(prepare_service)->STARTED->(run_service)->STOPPING->(finalize_service)->STOPPED

INITIALIZED class-attribute instance-attribute

INITIALIZED = 'INITIALIZED'

The service has been created, but has not been started yet

STARTED class-attribute instance-attribute

STARTED = 'STARTED'

The service is running.

STARTING class-attribute instance-attribute

STARTING = 'STARTING'

The service is starting, but is not running yet

STOPPED class-attribute instance-attribute

STOPPED = 'STOPPED'

The service is not running anymore

STOPPING class-attribute instance-attribute

STOPPING = 'STOPPING'

The service is in the process of stopping