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
impl DatabaseQueue
Sourcepub fn with_tables(db: Database, jobs: &str, failed: &str) -> Result<Self>
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.
pub fn database(&self) -> &Database
Sourcepub async fn migrate(&self) -> Result<()>
pub async fn migrate(&self) -> Result<()>
Create the tables directly, for an application that would rather not
register CreateQueueTables in its migration registry.
Sourcepub async fn drop_tables(&self) -> Result<()>
pub async fn drop_tables(&self) -> Result<()>
Drop the tables. Intended for tests and queue:fresh.
Sourcepub async fn reclaim_expired(&self, queue: &str) -> Result<u64>
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
impl Clone for DatabaseQueue
Source§impl Queue for DatabaseQueue
impl Queue for DatabaseQueue
Source§fn driver(&self) -> &'static str
fn driver(&self) -> &'static str
queue.* events and error messages,
which is how Telescope shows which backend handled a job.Source§fn push(&self, job: QueuedJob) -> BoxFuture<'_, Result<String>>
fn push(&self, job: QueuedJob) -> BoxFuture<'_, Result<String>>
Source§fn pop<'a>(
&'a self,
queue: &'a str,
) -> BoxFuture<'a, Result<Option<ReservedJob>>>
fn pop<'a>( &'a self, queue: &'a str, ) -> BoxFuture<'a, Result<Option<ReservedJob>>>
None when there is nothing ready. Read moreSource§fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
Source§fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>
fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>
Source§fn release<'a>(
&'a self,
job: &'a ReservedJob,
delay: Duration,
) -> BoxFuture<'a, Result<()>>
fn release<'a>( &'a self, job: &'a ReservedJob, delay: Duration, ) -> BoxFuture<'a, Result<()>>
delay. Read moreSource§fn fail<'a>(
&'a self,
job: &'a ReservedJob,
error: &'a str,
) -> BoxFuture<'a, Result<()>>
fn fail<'a>( &'a self, job: &'a ReservedJob, error: &'a str, ) -> BoxFuture<'a, Result<()>>
Source§fn failed_jobs(&self) -> BoxFuture<'_, Result<Vec<FailedJob>>>
fn failed_jobs(&self) -> BoxFuture<'_, Result<Vec<FailedJob>>>
Source§fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseQueue
impl !UnwindSafe for DatabaseQueue
impl Freeze for DatabaseQueue
impl Send for DatabaseQueue
impl Sync for DatabaseQueue
impl Unpin for DatabaseQueue
impl UnsafeUnpin for DatabaseQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> QueueExt for T
impl<T> QueueExt for T
Source§fn dispatch_chain<'a>(&'a self, chain: Chain) -> BoxFuture<'a, Result<String>>
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.