mas_storage::queue

Trait QueueJobRepository

source
pub trait QueueJobRepository: Send + Sync {
    type Error;

    // Required methods
    fn schedule<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 mut self,
        rng: &'life1 mut (dyn RngCore + Send),
        clock: &'life2 dyn Clock,
        queue_name: &'life3 str,
        payload: Value,
        metadata: Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn reserve<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 mut self,
        clock: &'life1 dyn Clock,
        worker: &'life2 Worker,
        queues: &'life3 [&'life4 str],
        count: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait;
    fn mark_as_completed<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        clock: &'life1 dyn Clock,
        id: Ulid,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn mark_as_failed<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        clock: &'life1 dyn Clock,
        id: Ulid,
        reason: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn retry<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        rng: &'life1 mut (dyn RngCore + Send),
        clock: &'life2 dyn Clock,
        id: Ulid,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

A QueueJobRepository is used to schedule jobs to be executed by a worker.

Required Associated Types§

source

type Error

The error type returned by the repository.

Required Methods§

source

fn schedule<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, rng: &'life1 mut (dyn RngCore + Send), clock: &'life2 dyn Clock, queue_name: &'life3 str, payload: Value, metadata: Value, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Schedule a job to be executed as soon as possible by a worker.

§Parameters
  • rng - The random number generator used to generate a new job ID
  • clock - The clock used to generate timestamps
  • queue_name - The name of the queue to schedule the job on
  • payload - The payload of the job
  • metadata - Arbitrary metadata about the job scheduled immediately.
§Errors

Returns an error if the underlying repository fails.

source

fn reserve<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, worker: &'life2 Worker, queues: &'life3 [&'life4 str], count: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Reserve multiple jobs from multiple queues

§Parameters
  • clock - The clock used to generate timestamps
  • worker - The worker that is reserving the jobs
  • queues - The queues to reserve jobs from
  • count - The number of jobs to reserve
§Errors

Returns an error if the underlying repository fails.

source

fn mark_as_completed<'life0, 'life1, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a job as completed

§Parameters
  • clock - The clock used to generate timestamps
  • id - The ID of the job to mark as completed
§Errors

Returns an error if the underlying repository fails.

source

fn mark_as_failed<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, id: Ulid, reason: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Marks a job as failed.

§Parameters
  • clock - The clock used to generate timestamps
  • id - The ID of the job to mark as failed
  • reason - The reason for the failure
§Errors

Returns an error if the underlying repository fails.

source

fn retry<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, rng: &'life1 mut (dyn RngCore + Send), clock: &'life2 dyn Clock, id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retry a job.

§Parameters
  • rng - The random number generator used to generate a new job ID
  • clock - The clock used to generate timestamps
  • id - The ID of the job to reschedule
§Errors

Returns an error if the underlying repository fails.

Implementations on Foreign Types§

source§

impl<R> QueueJobRepository for Box<R>

source§

type Error = <R as QueueJobRepository>::Error

source§

fn schedule<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, rng: &'life1 mut (dyn RngCore + Send), clock: &'life2 dyn Clock, queue_name: &'life3 str, payload: Value, metadata: Value, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

source§

fn reserve<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, worker: &'life2 Worker, queues: &'life3 [&'life4 str], count: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

source§

fn mark_as_completed<'life0, 'life1, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

fn mark_as_failed<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, clock: &'life1 dyn Clock, id: Ulid, reason: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

source§

fn retry<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, rng: &'life1 mut (dyn RngCore + Send), clock: &'life2 dyn Clock, id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Implementors§

source§

impl<R, F, E> QueueJobRepository for MapErr<R, F>
where R: QueueJobRepository, F: FnMut(<R as QueueJobRepository>::Error) -> E + Send + Sync,

source§

type Error = E