Skip to main content

Queue

Struct Queue 

Source
pub struct Queue { /* private fields */ }
Expand description

Job queue backed by Redis.

Implementations§

Source§

impl Queue

Source

pub async fn new( redis_url: impl Into<String>, queue_name: impl Into<String>, ) -> QueueResult<Self>

Create a new queue.

Source

pub async fn with_config(config: QueueConfig) -> QueueResult<Self>

Create a queue with custom configuration.

Source

pub async fn enqueue( &self, job_type: impl Into<String>, data: JobData, ) -> QueueResult<JobId>

Enqueue a job.

Source

pub async fn enqueue_in( &self, delay: Duration, job_type: impl Into<String>, data: JobData, ) -> QueueResult<JobId>

Enqueue a job to run after a delay.

Convenience wrapper over Job::schedule_after + enqueue_job: the job lands in the delayed set and is promoted once due.

Source

pub async fn enqueue_at( &self, when: DateTime<Utc>, job_type: impl Into<String>, data: JobData, ) -> QueueResult<JobId>

Enqueue a job to run at a specific time.

Convenience wrapper over Job::schedule_at + enqueue_job: the job lands in the delayed set and is promoted once its scheduled time passes.

Source

pub async fn enqueue_job(&self, job: Job) -> QueueResult<JobId>

Enqueue a job with options.

Source

pub async fn dequeue(&self) -> QueueResult<Option<Job>>

Dequeue the next job.

Source

pub async fn complete(&self, job_id: JobId) -> QueueResult<()>

Complete a job.

Source

pub async fn fail(&self, job_id: JobId, error: String) -> QueueResult<()>

Fail a job.

Source

pub async fn requeue(&self, job: &Job) -> QueueResult<()>

Return a dequeued-but-unprocessed job to its pending priority queue.

A job popped by dequeue has already been marked processing (attempt incremented) and placed in the processing set. When the caller cannot run it after all (e.g. a batch consumer that dequeued the wrong job type), this puts it back on its priority queue and removes it from processing, undoing the start_processing bookkeeping so the requeue does not burn a retry attempt. Without this the job would be orphaned in processing forever (data loss).

Source

pub async fn get_job(&self, job_id: JobId) -> QueueResult<Option<Job>>

Get a job by ID.

Source

pub async fn size(&self) -> QueueResult<usize>

Get queue size.

Source

pub async fn backlog_size(&self) -> QueueResult<usize>

Total number of jobs occupying the queue, for max_size enforcement.

Unlike size, which counts only ready pending:* jobs, this also counts delayed/scheduled jobs and in-flight processing jobs – every job that holds a slot against the configured cap. Pipelined into one round-trip.

Source

pub async fn processing_len(&self) -> QueueResult<usize>

Number of jobs currently in the in-flight processing set.

Source

pub async fn reclaim_stale( &self, visibility_timeout: Duration, ) -> QueueResult<usize>

Return jobs whose in-flight claim is older than visibility_timeout to their pending priority queues, and report how many were reclaimed.

dequeue records a claim timestamp in the processing set, but nothing else ever reads it back: if a worker crashes, is SIGKILLed, or its handler task panics, its job is in no pending queue and no retry path will ever pick it up. This is the reaper that closes that hole, and Worker::start runs it periodically in the background.

visibility_timeout must exceed the longest a job may legitimately stay in flight (i.e. at least WorkerConfig::job_timeout), otherwise a job that is merely slow will be re-filed and run twice. Handlers should be idempotent regardless, since a crash after the handler’s side effects but before complete() is indistinguishable from a crash before them.

Reclaimed jobs re-enter the queue with their attempts counter as the crashed worker left it, so a job that reliably kills its worker still exhausts max_attempts and lands in the dead-letter set rather than looping forever.

Source

pub async fn clear(&self) -> QueueResult<()>

Clear all jobs from the queue.

Trait Implementations§

Source§

impl Clone for Queue

Source§

fn clone(&self) -> Queue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Queue

§

impl !UnwindSafe for Queue

§

impl Freeze for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl UnsafeUnpin for Queue

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.