Skip to main content

QueueStore

Trait QueueStore 

Source
pub trait QueueStore {
Show 13 methods // Required methods fn push_job(&mut self, job: QueueJob) -> ThingdResult<QueueJob>; fn claim_job_with_options( &mut self, queue: &str, options: QueueClaimOptions, ) -> ThingdResult<Option<QueueJob>>; fn ack_job( &mut self, queue: &str, id: &str, ) -> ThingdResult<Option<QueueJob>>; fn nack_job_with_options( &mut self, queue: &str, id: &str, options: QueueNackOptions, ) -> ThingdResult<Option<QueueJob>>; fn list_jobs(&self, queue: &str) -> ThingdResult<Vec<QueueJob>>; fn list_dead_jobs(&self, queue: &str) -> ThingdResult<Vec<QueueJob>>; fn list_queues(&self) -> ThingdResult<Vec<String>>; fn count_active_jobs(&self) -> ThingdResult<u64>; fn count_dead_jobs(&self) -> ThingdResult<u64>; // Provided methods fn push_jobs_batch( &mut self, jobs: Vec<QueueJob>, ) -> ThingdResult<Vec<QueueJob>> { ... } fn claim_job(&mut self, queue: &str) -> ThingdResult<Option<QueueJob>> { ... } fn claim_and_ack( &mut self, queue: &str, options: QueueClaimOptions, ) -> ThingdResult<Option<QueueJob>> { ... } fn nack_job( &mut self, queue: &str, id: &str, ) -> ThingdResult<Option<QueueJob>> { ... }
}
Expand description

Queue storage operations.

§Examples

use thingd_core::{MemoryEngine, QueueStore, QueueJob, QueueJobStatus};

let mut store = MemoryEngine::new();
let job = QueueJob::new("emails", "job-1", r#"{"to":"alice@example.com"}"#, 3);
store.push_job(job).unwrap();

let claimed = store.claim_job("emails").unwrap();
assert!(claimed.is_some());
let job = claimed.unwrap();
assert_eq!(job.status, QueueJobStatus::Leased);

let completed = store.ack_job("emails", &job.id).unwrap();
assert_eq!(completed.unwrap().status, QueueJobStatus::Completed);

Required Methods§

Source

fn push_job(&mut self, job: QueueJob) -> ThingdResult<QueueJob>

Push a job onto a queue.

§Errors

Returns an error when the backing store cannot persist the job.

Source

fn claim_job_with_options( &mut self, queue: &str, options: QueueClaimOptions, ) -> ThingdResult<Option<QueueJob>>

Claim the next ready job from a queue with explicit options.

§Errors

Returns an error when the backing store cannot claim a job.

Source

fn ack_job(&mut self, queue: &str, id: &str) -> ThingdResult<Option<QueueJob>>

Acknowledge a leased job as completed.

§Errors

Returns an error when the backing store cannot update the job.

Source

fn nack_job_with_options( &mut self, queue: &str, id: &str, options: QueueNackOptions, ) -> ThingdResult<Option<QueueJob>>

Reject a leased job for retry or dead-letter routing with explicit options.

§Errors

Returns an error when the backing store cannot update the job.

Source

fn list_jobs(&self, queue: &str) -> ThingdResult<Vec<QueueJob>>

List all jobs in a queue.

§Errors

Returns an error when the backing store cannot read queue jobs.

Source

fn list_dead_jobs(&self, queue: &str) -> ThingdResult<Vec<QueueJob>>

List dead-letter jobs in a queue.

§Errors

Returns an error when the backing store cannot read dead-letter jobs.

Source

fn list_queues(&self) -> ThingdResult<Vec<String>>

List all unique queue names.

§Errors

Returns an error when the backing store cannot list queues.

Source

fn count_active_jobs(&self) -> ThingdResult<u64>

Count total active jobs across all queues.

§Errors

Returns an error when the backing store cannot count active jobs.

Source

fn count_dead_jobs(&self) -> ThingdResult<u64>

Count total dead-letter jobs across all queues.

§Errors

Returns an error when the backing store cannot count dead jobs.

Provided Methods§

Source

fn push_jobs_batch( &mut self, jobs: Vec<QueueJob>, ) -> ThingdResult<Vec<QueueJob>>

Push multiple jobs onto a queue in a single transaction.

This is significantly faster than calling push_job in a loop.

§Errors

Returns an error when the backing store cannot persist any job.

Source

fn claim_job(&mut self, queue: &str) -> ThingdResult<Option<QueueJob>>

Claim the next ready job from a queue.

§Errors

Returns an error when the backing store cannot claim a job.

Source

fn claim_and_ack( &mut self, queue: &str, options: QueueClaimOptions, ) -> ThingdResult<Option<QueueJob>>

Claim and immediately ack a job in a single transaction.

This is faster than calling claim_job + ack_job separately because it avoids per-operation transaction overhead.

§Errors

Returns an error when the backing store cannot claim or ack the job.

Source

fn nack_job(&mut self, queue: &str, id: &str) -> ThingdResult<Option<QueueJob>>

Reject a leased job for retry or dead-letter routing.

§Errors

Returns an error when the backing store cannot update the job.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§