Struct apalis::prelude::Monitor

source ·
pub struct Monitor<E> { /* private fields */ }
Expand description

A monitor for coordinating and managing a collection of workers.

Implementations§

source§

impl<E> Monitor<E>
where E: Executor + Clone + Send + 'static + Sync,

source

pub fn register<J, S, P>(self, worker: Worker<Ready<S, P>>) -> Monitor<E>
where J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static, <S as Service<Request<J>>>::Future: Send, <S as Service<Request<J>>>::Response: 'static, <S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>, <P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,

Registers a single instance of a Worker

source

pub fn register_with_count<J, S, P>( self, count: usize, worker: Worker<Ready<S, P>> ) -> Monitor<E>
where J: Send + Sync + 'static, S: Service<Request<J>> + Send + 'static + Clone, P: Backend<Request<J>> + 'static, <S as Service<Request<J>>>::Future: Send, <S as Service<Request<J>>>::Response: 'static, <S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>, <P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,

Registers multiple workers with the monitor.

§Arguments
  • count - The number of workers to register.
  • worker - A Worker that is ready for running.
§Returns

The monitor instance, with all workers added to the collection.

source

pub async fn run_with_signal<S>(self, signal: S) -> Result<(), Error>
where S: Future<Output = Result<(), Error>>, E: Executor + Clone + Send + 'static,

Runs the monitor and all its registered workers until they have all completed or a shutdown signal is received.

§Arguments
  • signal - A Future that resolves when a shutdown signal is received.
§Errors

If the monitor fails to shutdown gracefully, an std::io::Error will be returned.

source

pub async fn run(self) -> Result<(), Error>
where E: Executor + Clone + Send + 'static,

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

pub fn on_event<F>(self, f: F) -> Monitor<E>
where F: Fn(Worker<Event>) + Send + Sync + 'static,

Handles events emitted

source

pub fn executor(&self) -> &E

Get the current executor

source§

impl<E> Monitor<E>

source

pub fn new() -> Monitor<E>
where E: Default,

Creates a new monitor instance.

§Returns

A new monitor instance, with an empty collection of workers.

source

pub fn new_with_executor(executor: E) -> Monitor<E>

Creates a new monitor instance with an executor

§Returns

A new monitor instance, with an empty collection of workers.

source

pub fn set_executor<NE>(self, executor: NE) -> Monitor<NE>
where NE: Executor,

Sets a custom executor for the monitor, allowing the usage of another runtime apart from Tokio. The executor must implement the Executor trait.

source

pub fn shutdown_timeout(self, duration: Duration) -> Monitor<E>

Sets a timeout duration for the monitor’s shutdown process.

§Arguments
  • duration - The timeout duration.
§Returns

The monitor instance, with the shutdown timeout duration set.

source

pub fn with_terminator( self, fut: impl Future<Output = ()> + Send + 'static ) -> Monitor<E>

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.

Trait Implementations§

source§

impl<E> Debug for Monitor<E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<E> Default for Monitor<E>
where E: Default,

source§

fn default() -> Monitor<E>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Monitor<E>
where E: Freeze,

§

impl<E> !RefUnwindSafe for Monitor<E>

§

impl<E> Send for Monitor<E>
where E: Send,

§

impl<E> !Sync for Monitor<E>

§

impl<E> Unpin for Monitor<E>
where E: Unpin,

§

impl<E> !UnwindSafe for Monitor<E>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more