Skip to main content

BackgroundService

Trait BackgroundService 

Source
pub trait BackgroundService {
    // Provided methods
    fn start_with_ready_notifier<'life0, 'async_trait>(
        &'life0 self,
        shutdown: ShutdownWatch,
        ready_notifier: ServiceReadyNotifier,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn start<'life0, 'async_trait>(
        &'life0 self,
        _shutdown: ShutdownWatch,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

The background service interface

You can implement a background service with or without the ready notifier, but you shouldn’t implement both. Under the hood, the pingora service will call the start_with_ready_notifier function. By default this function will call the regular start function.

Provided Methods§

Source

fn start_with_ready_notifier<'life0, 'async_trait>( &'life0 self, shutdown: ShutdownWatch, ready_notifier: ServiceReadyNotifier, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

This function is called when the pingora server tries to start all the services. The background service should signal readiness by calling ready_notifier.notify_ready() once initialization is complete. The service can return at anytime or wait for the shutdown signal.

By default this method will immediately signal readiness and call through to the regular start function

Source

fn start<'life0, 'async_trait>( &'life0 self, _shutdown: ShutdownWatch, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

This function is called when the pingora server tries to start all the services. The background service can return at anytime or wait for the shutdown signal.

Implementors§