pub struct Storage { /* private fields */ }Expand description
Storage provides the main interface for job management in Oxanus.
It handles all job operations including enqueueing, scheduling, and monitoring.
Storage instances are created using the Storage::builder() method.
§Examples
use oxanus::{Storage, Queue, Worker};
async fn example() -> Result<(), oxanus::OxanusError> {
let storage = Storage::builder().from_env()?.build()?;
// Enqueue a job
storage.enqueue(MyQueue, MyWorker { data: "hello" }).await?;
// Schedule a job for later
storage.enqueue_in(MyQueue, MyWorker { data: "delayed" }, 300).await?;
Ok(())
}Implementations§
Source§impl Storage
impl Storage
Sourcepub fn builder() -> StorageBuilder
pub fn builder() -> StorageBuilder
Creates a new StorageBuilder for configuring and building a Storage instance.
§Examples
use oxanus::Storage;
let builder = Storage::builder();
let storage = builder.from_env()?.build()?;Sourcepub async fn enqueue<T, DT, ET>(
&self,
queue: impl Queue,
job: T,
) -> Result<JobId, OxanusError>
pub async fn enqueue<T, DT, ET>( &self, queue: impl Queue, job: T, ) -> Result<JobId, OxanusError>
Enqueues a job to be processed immediately.
§Arguments
queue- The queue to enqueue the job tojob- The job to enqueue
§Returns
A JobId that can be used to track the job, or an OxanusError if the operation fails.
§Examples
use oxanus::{Storage, Queue, Worker};
async fn example(storage: &Storage) -> Result<(), oxanus::OxanusError> {
let job_id = storage.enqueue(MyQueue, MyWorker { data: "hello" }).await?;
Ok(())
}Sourcepub async fn enqueue_in<T, DT, ET>(
&self,
queue: impl Queue,
job: T,
delay: u64,
) -> Result<JobId, OxanusError>
pub async fn enqueue_in<T, DT, ET>( &self, queue: impl Queue, job: T, delay: u64, ) -> Result<JobId, OxanusError>
Enqueues a job to be processed after a specified delay.
§Arguments
queue- The queue to enqueue the job tojob- The job to enqueuedelay- The delay in seconds before the job should be processed
§Returns
A JobId that can be used to track the job, or an OxanusError if the operation fails.
§Examples
use oxanus::{Storage, Queue, Worker};
async fn example(storage: &Storage) -> Result<(), oxanus::OxanusError> {
// Schedule a job to run in 5 minutes
let job_id = storage.enqueue_in(MyQueue, MyWorker { data: "delayed" }, 300).await?;
Ok(())
}Sourcepub async fn enqueued_count(
&self,
queue: impl Queue,
) -> Result<usize, OxanusError>
pub async fn enqueued_count( &self, queue: impl Queue, ) -> Result<usize, OxanusError>
Returns the number of jobs currently enqueued in the specified queue.
§Arguments
queue- The queue to count jobs for
§Returns
The number of enqueued jobs, or an OxanusError if the operation fails.
Sourcepub async fn latency_ms(&self, queue: impl Queue) -> Result<f64, OxanusError>
pub async fn latency_ms(&self, queue: impl Queue) -> Result<f64, OxanusError>
Returns the latency of the queue (The age of the oldest job in the queue).
§Arguments
queue- The queue to get the latency for
§Returns
The latency of the queue in milliseconds, or an OxanusError if the operation fails.
Sourcepub async fn dead_count(&self) -> Result<usize, OxanusError>
pub async fn dead_count(&self) -> Result<usize, OxanusError>
Returns the number of jobs that have failed and moved to the dead queue.
§Returns
The number of dead jobs, or an OxanusError if the operation fails.
Sourcepub async fn retries_count(&self) -> Result<usize, OxanusError>
pub async fn retries_count(&self) -> Result<usize, OxanusError>
Returns the number of jobs that are currently being retried.
§Returns
The number of retrying jobs, or an OxanusError if the operation fails.
Sourcepub async fn scheduled_count(&self) -> Result<usize, OxanusError>
pub async fn scheduled_count(&self) -> Result<usize, OxanusError>
Returns the number of jobs that are scheduled for future execution.
§Returns
The number of scheduled jobs, or an OxanusError if the operation fails.
Sourcepub async fn jobs_count(&self) -> Result<usize, OxanusError>
pub async fn jobs_count(&self) -> Result<usize, OxanusError>
Returns the number of jobs that are currently enqueued or scheduled for future execution.
§Returns
The number of jobs, or an OxanusError if the operation fails.
Sourcepub async fn stats(&self) -> Result<Stats, OxanusError>
pub async fn stats(&self) -> Result<Stats, OxanusError>
Returns the stats for all queues.
§Returns
The stats for all queues, or an OxanusError if the operation fails.
Sourcepub async fn processes(&self) -> Result<Vec<Process>, OxanusError>
pub async fn processes(&self) -> Result<Vec<Process>, OxanusError>
Returns the list of processes that are currently running.
§Returns
The list of processes, or an OxanusError if the operation fails.