Skip to main content

ServiceWithDependents

Trait ServiceWithDependents 

Source
pub trait ServiceWithDependents: Send + Sync {
    // Required methods
    fn start_service<'life0, 'async_trait>(
        &'life0 mut self,
        fds: Option<ListenFds>,
        shutdown: ShutdownWatch,
        listeners_per_fd: usize,
        ready_notifier: ServiceReadyNotifier,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn name(&self) -> &str;

    // Provided methods
    fn threads(&self) -> Option<usize> { ... }
    fn on_startup_delay(&self, time_waited: Duration) { ... }
}

Required Methods§

Source

fn start_service<'life0, 'async_trait>( &'life0 mut self, fds: Option<ListenFds>, shutdown: ShutdownWatch, listeners_per_fd: usize, ready_notifier: ServiceReadyNotifier, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

This function will be called when the server is ready to start the service.

Override this method if you need to control exactly when the service signals readiness (e.g., after async initialization is complete).

§Arguments
  • fds (Unix only): a collection of listening file descriptors. During zero downtime restart the fds would contain the listening sockets passed from the old service, services should take the sockets they need to use then. If the sockets the service looks for don’t appear in the collection, the service should create its own listening sockets and then put them into the collection in order for them to be passed to the next server.
  • shutdown: the shutdown signal this server would receive.
  • listeners_per_fd: number of listener tasks to spawn per file descriptor.
  • ready_notifier: notifier to signal when the service is ready. Services with dependents should call ready_notifier.notify_ready() once they are fully initialized.
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 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§