Skip to main content

Service

Trait Service 

Source
pub trait Service: Sync + Send {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn start_service<'life0, 'async_trait>(
        &'life0 mut self,
        _fds: Option<ListenFds>,
        _shutdown: ShutdownWatch,
        _listeners_per_fd: usize,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn threads(&self) -> Option<usize> { ... }
    fn on_startup_delay(&self, time_waited: Duration) { ... }
}
Expand description

The service interface

Required Methods§

Source

fn name(&self) -> &str

The name of the service, just for logging and naming the threads assigned to this service

Note that due to the limit of the underlying system, only the first 16 chars will be used

Provided Methods§

Source

fn start_service<'life0, 'async_trait>( &'life0 mut self, _fds: Option<ListenFds>, _shutdown: ShutdownWatch, _listeners_per_fd: usize, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the service without readiness notification.

This is a simpler version of Self::start_service() for services that don’t need to control when they signal readiness. The default implementation does nothing.

Most services should override this method instead of Self::start_service().

§Arguments
  • fds (Unix only): a collection of listening file descriptors.
  • shutdown: the shutdown signal this server would receive.
  • listeners_per_fd: number of listener tasks to spawn per file descriptor.
Source

fn threads(&self) -> Option<usize>

The preferred number of threads to run this service

If None, the global setting will be used

Source

fn on_startup_delay(&self, time_waited: Duration)

This is currently called to inform the service about the delay it experienced from between waiting on its dependencies. Default behavior is to log the time.

TODO. It would be nice if this function was called intermittently by the server while the service was waiting to give live updates while the service was waiting and allow the service to decide whether to keep waiting, continue anyway, or exit

Implementors§

Source§

impl<A: ServerApp + Send + Sync + 'static> Service for Service<A>