pub struct Queue { /* private fields */ }Expand description
Job queue backed by Redis.
Implementations§
Source§impl Queue
impl Queue
Sourcepub async fn new(
redis_url: impl Into<String>,
queue_name: impl Into<String>,
) -> QueueResult<Self>
pub async fn new( redis_url: impl Into<String>, queue_name: impl Into<String>, ) -> QueueResult<Self>
Create a new queue.
Sourcepub async fn with_config(config: QueueConfig) -> QueueResult<Self>
pub async fn with_config(config: QueueConfig) -> QueueResult<Self>
Create a queue with custom configuration.
Sourcepub async fn enqueue(
&self,
job_type: impl Into<String>,
data: JobData,
) -> QueueResult<JobId>
pub async fn enqueue( &self, job_type: impl Into<String>, data: JobData, ) -> QueueResult<JobId>
Enqueue a job.
Sourcepub async fn enqueue_in(
&self,
delay: Duration,
job_type: impl Into<String>,
data: JobData,
) -> QueueResult<JobId>
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.
Sourcepub async fn enqueue_at(
&self,
when: DateTime<Utc>,
job_type: impl Into<String>,
data: JobData,
) -> QueueResult<JobId>
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.
Sourcepub async fn enqueue_job(&self, job: Job) -> QueueResult<JobId>
pub async fn enqueue_job(&self, job: Job) -> QueueResult<JobId>
Enqueue a job with options.
Sourcepub async fn dequeue(&self) -> QueueResult<Option<Job>>
pub async fn dequeue(&self) -> QueueResult<Option<Job>>
Dequeue the next job.
Sourcepub async fn complete(&self, job_id: JobId) -> QueueResult<()>
pub async fn complete(&self, job_id: JobId) -> QueueResult<()>
Complete a job.
Sourcepub async fn requeue(&self, job: &Job) -> QueueResult<()>
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).
Sourcepub async fn size(&self) -> QueueResult<usize>
pub async fn size(&self) -> QueueResult<usize>
Get queue size.
Sourcepub async fn backlog_size(&self) -> QueueResult<usize>
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.
Sourcepub async fn processing_len(&self) -> QueueResult<usize>
pub async fn processing_len(&self) -> QueueResult<usize>
Number of jobs currently in the in-flight processing set.
Sourcepub async fn reclaim_stale(
&self,
visibility_timeout: Duration,
) -> QueueResult<usize>
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.
Sourcepub async fn clear(&self) -> QueueResult<()>
pub async fn clear(&self) -> QueueResult<()>
Clear all jobs from the queue.