Skip to main content

JobQueue

Trait JobQueue 

Source
pub trait JobQueue:
    Send
    + Sync
    + 'static {
    // Required methods
    fn register<'life0, 'async_trait, T>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where T: 'async_trait + Job,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn dispatch<'life0, 'life1, 'async_trait, T>(
        &'life0 self,
        payload: &'life1 T,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
       where T: 'async_trait + Job,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn start<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn pending_count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn register_with<'life0, 'async_trait, T, F, Fut>(
        &'life0 self,
        run: F,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where T: Job + 'async_trait,
             F: Fn(T) -> Fut + Send + Sync + 'static + 'async_trait,
             Fut: Future<Output = Result<(), JobError>> + Send + 'static + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Pluggable job-queue backend.

Required Methods§

Source

fn register<'life0, 'async_trait, T>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where T: 'async_trait + Job, Self: 'async_trait, 'life0: 'async_trait,

Register a job type. Must be called before dispatch::<T> or start.

Source

fn dispatch<'life0, 'life1, 'async_trait, T>( &'life0 self, payload: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
where T: 'async_trait + Job, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Enqueue a job for asynchronous execution.

Source

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

Spawn worker tasks. Calling start twice is a no-op; start after Self::shutdown starts a fresh set of workers.

Source

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

Stop all workers: running jobs get the shutdown grace period (DEFAULT_SHUTDOWN_GRACE), then are aborted and handed back to the queue. Queued jobs stay queued for the next start.

No signal reaches a running job, and an aborted one runs again from the start, so jobs are at-least-once: make them idempotent.

Source

fn pending_count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Number of jobs currently queued (waiting to be picked up).

Provided Methods§

Source

fn register_with<'life0, 'async_trait, T, F, Fut>( &'life0 self, run: F, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where T: Job + 'async_trait, F: Fn(T) -> Fut + Send + Sync + 'static + 'async_trait, Fut: Future<Output = Result<(), JobError>> + Send + 'static + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Register T with run in place of Job::run, so the handler can hold state the payload cannot carry, such as a mailer.

Both built-in queues override this. The default ignores run and registers Job::run, so a custom queue keeps compiling.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§