Struct apalis_core::monitor::Monitor
source · pub struct Monitor<E> { /* private fields */ }
Expand description
A monitor for coordinating and managing a collection of workers.
Implementations§
source§impl<E: Executor + Clone + Send + 'static + Sync> Monitor<E>
impl<E: Executor + Clone + Send + 'static + Sync> Monitor<E>
sourcepub fn register<J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static>(
self,
worker: Worker<Ready<S, P>>,
) -> Self
pub fn register<J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static>( self, worker: Worker<Ready<S, P>>, ) -> Self
Registers a single instance of a Worker
sourcepub fn register_with_count<J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static>(
self,
count: usize,
worker: Worker<Ready<S, P>>,
) -> Self
pub fn register_with_count<J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static>( self, count: usize, worker: Worker<Ready<S, P>>, ) -> Self
sourcepub async fn run_with_signal<S: Future<Output = Result<()>>>(
self,
signal: S,
) -> Result<()>
pub async fn run_with_signal<S: Future<Output = Result<()>>>( self, signal: S, ) -> Result<()>
sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Runs the monitor and all its registered workers until they have all completed.
§Errors
If the monitor fails to shutdown gracefully, an std::io::Error
will be returned.
§Remarks
If a timeout has been set using the shutdown_timeout
method, the monitor
will wait for all workers to complete up to the timeout duration before exiting.
If the timeout is reached and workers have not completed, the monitor will exit forcefully.
source§impl<E> Monitor<E>
impl<E> Monitor<E>
sourcepub fn new() -> Selfwhere
E: Default,
pub fn new() -> Selfwhere
E: Default,
Creates a new monitor instance.
§Returns
A new monitor instance, with an empty collection of workers.
sourcepub fn new_with_executor(executor: E) -> Self
pub fn new_with_executor(executor: E) -> Self
Creates a new monitor instance with an executor
§Returns
A new monitor instance, with an empty collection of workers.
sourcepub fn set_executor<NE: Executor>(self, executor: NE) -> Monitor<NE>
pub fn set_executor<NE: Executor>(self, executor: NE) -> Monitor<NE>
Sets a custom executor for the monitor, allowing the usage of another runtime apart from Tokio.
The executor must implement the Executor
trait.
sourcepub fn shutdown_timeout(self, duration: Duration) -> Self
pub fn shutdown_timeout(self, duration: Duration) -> Self
sourcepub fn with_terminator(
self,
fut: impl Future<Output = ()> + Send + 'static,
) -> Self
pub fn with_terminator( self, fut: impl Future<Output = ()> + Send + 'static, ) -> Self
Sets a future that will start being polled when the monitor’s shutdown process starts.
After shutdown has been initiated, the terminator
future will be run, and if it completes
before all tasks are completed the shutdown process will complete, thus finishing the
shutdown even if there are outstanding tasks. This can be useful for using a timeout or
signal (or combination) to force a full shutdown even if one or more tasks are taking
longer than expected to finish.