liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! SRV-043 R1: one mapping from beamr's readiness refusals to the server's
//! error, shared by the TCP and WebSocket connection processes for register and
//! rearm alike.

use beamr::scheduler::ReadinessError;

use crate::ServerError;

/// Which readiness call beamr refused.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum ReadinessCall {
    /// The connection's one registration.
    Register,
    /// A rearm of that registration.
    Rearm,
}

/// The server's error for `call`, refused by beamr with `error` for the
/// connection process `pid`: the server's stop as
/// [`ServerError::ReadinessClosedByStop`], every other refusal as
/// [`ServerError::ListenerAccept`] with the call named.
pub(super) fn readiness_refusal(
    pid: u64,
    call: ReadinessCall,
    error: &ReadinessError,
) -> ServerError {
    // beamr refuses with TeardownInProgress once the scheduler's teardown has
    // closed readiness admission: the server's own stop, not a fault.
    if *error == ReadinessError::TeardownInProgress {
        return ServerError::ReadinessClosedByStop { pid };
    }
    let verb = match call {
        ReadinessCall::Register => "register",
        ReadinessCall::Rearm => "rearm",
    };
    ServerError::ListenerAccept {
        message: format!("failed to {verb} connection readiness: {error}"),
    }
}