Skip to main content

RuntimeBackend

Trait RuntimeBackend 

Source
pub trait RuntimeBackend: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn connect<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list_instances<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Instance>, RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn watch<'life0, 'async_trait>(
        &'life0 self,
        tx: Sender<RuntimeEvent>,
        cancel: CancellationToken,
    ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A runtime backend that watches lifecycle events and resolves instance metadata.

Implementations are expected to:

  • Connect to the runtime API on connect()
  • Stream lifecycle events via the mpsc::Sender in watch()
  • Handle reconnection internally (emit BackendDisconnected/BackendReconnected)
  • Provide a point-in-time snapshot via list_instances()

Required Methods§

Source

fn name(&self) -> &'static str

Backend name for logging and status (e.g., “docker”, “podman”, “systemd”).

Source

fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempt to connect to the runtime API.

Returns an error if the runtime is not available (socket missing, permission denied, API unreachable).

Source

fn list_instances<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Instance>, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all currently running instances.

Used for reconciliation on startup: the caller diffs this list against Koi’s current registrations.

Source

fn watch<'life0, 'async_trait>( &'life0 self, tx: Sender<RuntimeEvent>, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Watch for lifecycle events, sending them to the provided channel.

This method should run until the cancellation token is triggered or the channel is closed. It should handle transient failures (API disconnects) by emitting BackendDisconnected, reconnecting, and emitting BackendReconnected with a fresh reconciliation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§