Skip to content

state_machine

State machine for parsing systemd unit journal entries.

Classes:

State dataclass

State()

Bases: ABC

Abstract base class for state machine states.

Methods:

  • parse

    Parse a journal entry and yield events, returning the next state.

parse abstractmethod

parse(entry: JournalEntry) -> Generator[Event, None, State]

Parse a journal entry and yield events, returning the next state.

SystemdUnitStateChange dataclass

SystemdUnitStateChange(old_state: State, new_state: State)

Event emitted when a systemd unit changes state.

Attributes:

  • old_state (State) –

    The previous state.

  • new_state (State) –

    The new state.

SystemdUnitStateMachine

SystemdUnitStateMachine(
    inner_state_factory: Callable[[], State | None],
    inner_state_on_exit: Callable[[State], None],
    unit_name: str,
)

State machine for tracking a systemd unit's state via journal entries.

Parameters:

  • inner_state_factory (Callable[[], State | None]) –

    Factory to create the running state.

  • inner_state_on_exit (Callable[[State], None]) –

    Callback when the unit stops.

  • unit_name (str) –

    The systemd unit name to monitor.

Classes:

  • Uninitialized

    State before the unit has started or after it stopped.

Methods:

  • consume

    Process journal entries, yielding events and state changes.

Uninitialized dataclass

Uninitialized(factory: Callable[[], State | None])

Bases: State

State before the unit has started or after it stopped.

Attributes:

  • factory (Callable[[], State | None]) –

    Factory function to create the initial running state. Called when the unit starts. Can be called multiple times if the unit restarts.

Methods:

  • __eq__

    Check equality with another Uninitialized state.

  • parse

    Try to instantiate an initial state, and parse the incoming entry with it.

__eq__

__eq__(value: object) -> bool

Check equality with another Uninitialized state.

parse

parse(entry: JournalEntry) -> Generator[Event, None, State]

Try to instantiate an initial state, and parse the incoming entry with it.

consume

consume(
    entries: list[JournalEntry],
) -> Generator[Event | SystemdUnitStateChange, None, None]

Process journal entries, yielding events and state changes.