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 clear(&self) -> QueueResult<()>
pub async fn clear(&self) -> QueueResult<()>
Clear all jobs from the queue.