Struct Storage

Source
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

Source

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()?;
Source

pub async fn enqueue<T, DT, ET>( &self, queue: impl Queue, job: T, ) -> Result<JobId, OxanusError>
where T: Worker<Context = DT, Error = ET> + Serialize, DT: Send + Sync + Clone + 'static, ET: Error + Send + Sync + 'static,

Enqueues a job to be processed immediately.

§Arguments
  • queue - The queue to enqueue the job to
  • job - 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(())
}
Source

pub async fn enqueue_in<T, DT, ET>( &self, queue: impl Queue, job: T, delay: u64, ) -> Result<JobId, OxanusError>
where T: Worker<Context = DT, Error = ET> + Serialize, DT: Send + Sync + Clone + 'static, ET: Error + Send + Sync + 'static,

Enqueues a job to be processed after a specified delay.

§Arguments
  • queue - The queue to enqueue the job to
  • job - The job to enqueue
  • delay - 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(())
}
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn namespace(&self) -> &str

Returns the namespace this storage instance is using.

§Returns

The namespace string.

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Storage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,