Trait Service

Source
pub trait Service: Send + Sync {
    // Required methods
    fn run_forever<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Never> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn heartbeat_ttl(&self) -> i32;
    fn set_heartbeat(&mut self, heartbeat: Arc<dyn Heartbeat + 'static>);
    fn is_healthy(&self) -> bool;

    // Provided method
    fn name(&self) -> String { ... }
}

Required Methods§

Source

fn run_forever<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Never> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The service is never expected to stop, it should do its job until externally shutdown.

Source

fn heartbeat_ttl(&self) -> i32

The maximum amount of seconds allowed between heartbeats before the service is deemed “dead”

Source

fn set_heartbeat(&mut self, heartbeat: Arc<dyn Heartbeat + 'static>)

The service should frequently call “beat” to indicate that it is still alive.

Source

fn is_healthy(&self) -> bool

The service should be able to self-diagnose any internal issues and report if there is a problem.

Provided Methods§

Source

fn name(&self) -> String

The name used to represent the service in the logs

Implementors§