Skip to main content

ForgeDaemon

Trait ForgeDaemon 

Source
pub trait ForgeDaemon:
    Send
    + Sync
    + 'static {
    // Required methods
    fn info() -> DaemonInfo;
    fn execute(
        ctx: &DaemonContext,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + '_>>;
}
Expand description

Trait for FORGE daemon handlers.

Daemons are long-running singleton tasks that run continuously in the background. They support leader election (only one instance in cluster), automatic restart on panic, and graceful shutdown.

Required Methods§

Source

fn info() -> DaemonInfo

Get daemon metadata.

Source

fn execute( ctx: &DaemonContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + '_>>

Execute the daemon.

The daemon should run in a loop and check ctx.shutdown_signal() to handle graceful shutdown. Example:

loop {
    // Do work
    tokio::select! {
        _ = tokio::time::sleep(Duration::from_secs(60)) => {}
        _ = ctx.shutdown_signal() => break,
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§