Skip to main content

DatabaseQueue

Struct DatabaseQueue 

Source
pub struct DatabaseQueue { /* private fields */ }
Expand description

A queue backed by two database tables.

Survives a restart, and is shared by every process pointed at the same database — which is the whole reason to prefer it over the memory driver.

Implementations§

Source§

impl DatabaseQueue

Source

pub fn new(db: Database) -> Self

Use the conventional jobs and failed_jobs tables.

Source

pub fn with_tables(db: Database, jobs: &str, failed: &str) -> Result<Self>

Use table names of your own. Validated and quoted here, once, for the database this queue is talking to — "jobs" on PostgreSQL and SQLite, `jobs` on MySQL, [jobs] on SQL Server. The shared quote_identifier helper always writes double quotes, which MySQL reads as a string literal rather than a table.

Source

pub fn database(&self) -> &Database

Source

pub async fn migrate(&self) -> Result<()>

Create the tables directly, for an application that would rather not register CreateQueueTables in its migration registry.

Source

pub async fn drop_tables(&self) -> Result<()>

Drop the tables. Intended for tests and queue:fresh.

Source

pub async fn reclaim_expired(&self, queue: &str) -> Result<u64>

Release jobs whose worker never came back.

A worker that is killed between reserving and finishing leaves reserved_at set forever. Once the job’s own retry_after has passed with no result, the job is assumed orphaned and goes back on the queue.

Called only when the queue looks empty, so the common path — a worker picking up one of many waiting jobs — pays nothing for it.

Trait Implementations§

Source§

impl Clone for DatabaseQueue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Queue for DatabaseQueue

Source§

fn driver(&self) -> &'static str

The driver’s name. It appears in queue.* events and error messages, which is how Telescope shows which backend handled a job.
Source§

fn push(&self, job: QueuedJob) -> BoxFuture<'_, Result<String>>

Store a job. Returns the driver’s identifier for it. Read more
Source§

fn pop<'a>( &'a self, queue: &'a str, ) -> BoxFuture<'a, Result<Option<ReservedJob>>>

Reserve the next available job, or None when there is nothing ready. Read more
Source§

fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>

How many jobs are waiting on a queue, including delayed ones.
Source§

fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>

Finish with a reserved job: it succeeded and is gone.
Source§

fn release<'a>( &'a self, job: &'a ReservedJob, delay: Duration, ) -> BoxFuture<'a, Result<()>>

Put a reserved job back, available again after delay. Read more
Source§

fn fail<'a>( &'a self, job: &'a ReservedJob, error: &'a str, ) -> BoxFuture<'a, Result<()>>

Move a reserved job to the dead-letter store with the error that killed it. It must no longer be on the queue afterwards.
Source§

fn failed_jobs(&self) -> BoxFuture<'_, Result<Vec<FailedJob>>>

Everything in the dead-letter store, oldest first.
Source§

fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>

Throw away every job waiting on a queue. Returns how many went.
Source§

fn push_on<'a>( &'a self, queue: &'a str, job: QueuedJob, ) -> BoxFuture<'a, Result<String>>

Store a job on a named queue, whatever the job itself asked for.
Source§

fn later<'a>( &'a self, delay: Duration, job: QueuedJob, ) -> BoxFuture<'a, Result<String>>

Store a job that only becomes visible to a worker after delay.

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, 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> QueueExt for T
where T: Queue + ?Sized,

Source§

fn dispatch_chain<'a>(&'a self, chain: Chain) -> BoxFuture<'a, Result<String>>

dispatch(SendWelcomeEmail { user_id }) — the everyday call. Push the first step of a chain; the worker pushes each next step as the one before it succeeds. Returns the first step’s id.
Source§

fn dispatch<'a, J: Job>(&'a self, job: &'a J) -> BoxFuture<'a, Result<String>>

Source§

fn dispatch_on<'a, J: Job>( &'a self, queue: &'a str, job: &'a J, ) -> BoxFuture<'a, Result<String>>

Dispatch onto a named queue instead of the job’s own.
Source§

fn dispatch_later<'a, J: Job>( &'a self, delay: Duration, job: &'a J, ) -> BoxFuture<'a, Result<String>>

Dispatch, but not before delay has passed.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.