pub trait QueueStore:
Send
+ Sync
+ 'static {
// Required methods
fn insert(&self, job: NewJob) -> BoxFuture<'_, Result<String, QueueError>>;
fn reserve<'a>(
&'a self,
queue: &'a str,
worker: &'a str,
now: i64,
) -> BoxFuture<'a, Result<Option<ReservedJob>, QueueError>>;
fn complete<'a>(
&'a self,
job: &'a ReservedJob,
) -> BoxFuture<'a, Result<(), QueueError>>;
fn release<'a>(
&'a self,
job: &'a ReservedJob,
worker: &'a str,
available_at: i64,
) -> BoxFuture<'a, Result<bool, QueueError>>;
fn fail<'a>(
&'a self,
job: &'a ReservedJob,
worker: &'a str,
error: &'a str,
now: i64,
) -> BoxFuture<'a, Result<bool, QueueError>>;
fn failed(&self) -> BoxFuture<'_, Result<Vec<FailedJob>, QueueError>>;
fn retry<'a>(
&'a self,
target: &'a RetryTarget,
now: i64,
) -> BoxFuture<'a, Result<u64, QueueError>>;
fn flush_failed(&self) -> BoxFuture<'_, Result<u64, QueueError>>;
fn pending_count<'a>(
&'a self,
queue: &'a str,
) -> BoxFuture<'a, Result<u64, QueueError>>;
// Provided method
fn failed_summary(
&self,
since: DateTime<Utc>,
limit: usize,
) -> BoxFuture<'_, Result<FailedSummary, QueueError>> { ... }
}Expand description
A queue driver implemented outside this crate (navree-redis’s Redis driver is one): where jobs wait, are reserved by workers and end up when they fail. Times are Unix milliseconds from the app’s clock, passed in by the queue; a store never reads its own clock to decide what is due.
The built-in database and memory drivers have the same semantics,
which a store must keep:
- Order.
reservetakes the job of the queue with the smallest(available_at, id)among those a worker may take: unreserved jobs whoseavailable_athas come, and reserved jobs whose reservation is older thanNewJob::stale_after_ms(a crashed worker’s). Ids are UUID v7, so equal times run in dispatch order. - Atomic reservations. Two workers never reserve the same job at the same time. Reserving counts an attempt and records the worker.
- Ownership.
releaseandfailact only whileworkerstill holds the reservation, and returnfalseotherwise (the job was taken over). - Unique jobs. A job with a
unique_keyis not stored while a pending job with the same key blocks it (NewJob::blocked_by);insertreturns the pending job’s id. An older pending job that no longer blocks loses its key. - Failed jobs are kept until
retry(which puts them back withFailedJob::requeued) orflush_failed. - Membership. A job’s
membership(its operation) is stored with it and handed back on theReservedJob. Batches need thedatabaseormemorydriver: dispatching one on another driver is an error.
Select a store with queue.driver: redis resolves the provider of
dyn QueueStore named redis. Jobs dispatched inside a unit of work
are inserted after it commits.
Required Methods§
Sourcefn insert(&self, job: NewJob) -> BoxFuture<'_, Result<String, QueueError>>
fn insert(&self, job: NewJob) -> BoxFuture<'_, Result<String, QueueError>>
Stores job; returns its id, or the id of the pending unique job
that takes its place.
Sourcefn reserve<'a>(
&'a self,
queue: &'a str,
worker: &'a str,
now: i64,
) -> BoxFuture<'a, Result<Option<ReservedJob>, QueueError>>
fn reserve<'a>( &'a self, queue: &'a str, worker: &'a str, now: i64, ) -> BoxFuture<'a, Result<Option<ReservedJob>, QueueError>>
Reserves the next job of queue for worker at now: increments
its attempts and records the reservation. None when no job is
available.
Sourcefn complete<'a>(
&'a self,
job: &'a ReservedJob,
) -> BoxFuture<'a, Result<(), QueueError>>
fn complete<'a>( &'a self, job: &'a ReservedJob, ) -> BoxFuture<'a, Result<(), QueueError>>
Deletes job, which finished.
Sourcefn release<'a>(
&'a self,
job: &'a ReservedJob,
worker: &'a str,
available_at: i64,
) -> BoxFuture<'a, Result<bool, QueueError>>
fn release<'a>( &'a self, job: &'a ReservedJob, worker: &'a str, available_at: i64, ) -> BoxFuture<'a, Result<bool, QueueError>>
Unreserves job, available again at available_at. false when
worker no longer holds the reservation.
Sourcefn fail<'a>(
&'a self,
job: &'a ReservedJob,
worker: &'a str,
error: &'a str,
now: i64,
) -> BoxFuture<'a, Result<bool, QueueError>>
fn fail<'a>( &'a self, job: &'a ReservedJob, worker: &'a str, error: &'a str, now: i64, ) -> BoxFuture<'a, Result<bool, QueueError>>
Moves job to the failed jobs with error, failed at now.
false when worker no longer holds the reservation.
Sourcefn failed(&self) -> BoxFuture<'_, Result<Vec<FailedJob>, QueueError>>
fn failed(&self) -> BoxFuture<'_, Result<Vec<FailedJob>, QueueError>>
Every failed job, newest first (by failed_at, then id).
Sourcefn retry<'a>(
&'a self,
target: &'a RetryTarget,
now: i64,
) -> BoxFuture<'a, Result<u64, QueueError>>
fn retry<'a>( &'a self, target: &'a RetryTarget, now: i64, ) -> BoxFuture<'a, Result<u64, QueueError>>
Moves the targeted failed jobs back to their queues at now
(FailedJob::requeued); returns how many (0 for an unknown id).
Sourcefn flush_failed(&self) -> BoxFuture<'_, Result<u64, QueueError>>
fn flush_failed(&self) -> BoxFuture<'_, Result<u64, QueueError>>
Deletes every failed job; returns how many.
Sourcefn pending_count<'a>(
&'a self,
queue: &'a str,
) -> BoxFuture<'a, Result<u64, QueueError>>
fn pending_count<'a>( &'a self, queue: &'a str, ) -> BoxFuture<'a, Result<u64, QueueError>>
How many jobs of queue are not finished: waiting, delayed or
reserved.
Provided Methods§
Sourcefn failed_summary(
&self,
since: DateTime<Utc>,
limit: usize,
) -> BoxFuture<'_, Result<FailedSummary, QueueError>>
fn failed_summary( &self, since: DateTime<Utc>, limit: usize, ) -> BoxFuture<'_, Result<FailedSummary, QueueError>>
How many jobs failed, how many of them at or after since, and the
newest limit. By default it reads failed;
a store that can count without reading every job should.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".