Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
Show 24 methods // Required methods fn run_migrations<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn enqueue<'life0, 'async_trait>( &'life0 self, job: NewJob, ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe<'life0, 'life1, 'async_trait>( &'life0 self, queue: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<NotificationStream>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn lease_jobs_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn reap_expired_locks<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn start_attempts_batch<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, dataset_ids: &'life1 [String], job_ids: &'life2 [Uuid], worker_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, Uuid, i32)>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn mark_succeeded<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn mark_succeeded_batch<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, dataset_id: &'life1 str, updates: &'life2 [(Uuid, Uuid, i32)], worker_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn reschedule_for_retry<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, next_run_at: DateTime<Utc>, error_code: &'life2 str, error_message: &'life3 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn mark_dlq<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, reason_code: &'life2 str, error_code: &'life3 str, error_message: &'life4 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait; fn archive_succeeded_older_than<'life0, 'async_trait>( &'life0 self, cutoff: DateTime<Utc>, limit: i64, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn delete_history_for_succeeded_older_than<'life0, 'async_trait>( &'life0 self, cutoff: DateTime<Utc>, limit: i64, ) -> Pin<Box<dyn Future<Output = Result<(u64, u64)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_job<'life0, 'async_trait>( &'life0 self, job_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<Job>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_jobs<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: Option<&'life1 str>, status: Option<&'life2 str>, limit: i64, cursor_created_at: Option<DateTime<Utc>>, cursor_id: Option<Uuid>, ) -> Pin<Box<dyn Future<Output = Result<Vec<JobListItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn replay_job<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, override_queue: Option<&'life1 str>, override_run_at: Option<DateTime<Utc>>, ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; // Provided methods fn as_stream(&self) -> Option<&dyn StreamBackend> { ... } fn lease_jobs_batch_with_ordering<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ordering: QueueOrdering, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn perform_maintenance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn extend_lease<'life0, 'life1, 'async_trait>( &'life0 self, _job_id: Uuid, _worker_id: &'life1 str, _lease_seconds: i64, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn dequeue_and_lease<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn complete_job<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn retry_job<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, next_run_at: DateTime<Utc>, error_code: &'life2 str, error_message: &'life3 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn fail_job<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, reason_code: &'life2 str, error_code: &'life3 str, error_message: &'life4 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait { ... }
}
Expand description

Async, backend-agnostic storage interface for job queue operations.

Implementations of StorageBackend manage job persistence, leasing, retry scheduling, Dead-Letter Queue (DLQ) routing, maintenance archiving, and health probes.

Required Methods§

Source

fn run_migrations<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes backend schema migrations or setup steps.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs a health check to verify backend connectivity and readiness.

Source

fn enqueue<'life0, 'async_trait>( &'life0 self, job: NewJob, ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enqueues a new job into the backend queue.

Source

fn subscribe<'life0, 'life1, 'async_trait>( &'life0 self, queue: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<NotificationStream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Subscribes to job enqueue notification events for a specific queue.

Source

fn lease_jobs_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Leases up to batch_size runnable jobs for a specified worker ID.

Source

fn reap_expired_locks<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reaps expired locks from inactive workers, resetting their status back to queued.

Source

fn start_attempts_batch<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, dataset_ids: &'life1 [String], job_ids: &'life2 [Uuid], worker_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, Uuid, i32)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Starts job execution attempt records, returning (job_id, attempt_id, attempt_number) tuples.

Source

fn mark_succeeded<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Marks a single job execution attempt as succeeded.

Source

fn mark_succeeded_batch<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, dataset_id: &'life1 str, updates: &'life2 [(Uuid, Uuid, i32)], worker_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Marks a batch of job execution attempts as succeeded.

Source

fn reschedule_for_retry<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, next_run_at: DateTime<Utc>, error_code: &'life2 str, error_message: &'life3 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Records a failed attempt and reschedules the job for a future retry attempt.

Source

fn mark_dlq<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, reason_code: &'life2 str, error_code: &'life3 str, error_message: &'life4 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Records a failed attempt and transitions the job to the Dead-Letter Queue (DLQ).

Source

fn archive_succeeded_older_than<'life0, 'async_trait>( &'life0 self, cutoff: DateTime<Utc>, limit: i64, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Moves succeeded jobs older than cutoff into an archive table or storage location.

Source

fn delete_history_for_succeeded_older_than<'life0, 'async_trait>( &'life0 self, cutoff: DateTime<Utc>, limit: i64, ) -> Pin<Box<dyn Future<Output = Result<(u64, u64)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Prunes attempt audit logs and decision records for succeeded jobs older than cutoff.

Source

fn get_job<'life0, 'async_trait>( &'life0 self, job_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<Job>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetches a single job record by ID.

Source

fn list_jobs<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: Option<&'life1 str>, status: Option<&'life2 str>, limit: i64, cursor_created_at: Option<DateTime<Utc>>, cursor_id: Option<Uuid>, ) -> Pin<Box<dyn Future<Output = Result<Vec<JobListItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetches a list of jobs matching filters with cursor pagination.

Source

fn replay_job<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, override_queue: Option<&'life1 str>, override_run_at: Option<DateTime<Utc>>, ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Atomically replays a job by ID into the queue.

Provided Methods§

Source

fn as_stream(&self) -> Option<&dyn StreamBackend>

Returns reference to StreamBackend if supported by this storage implementation.

Source

fn lease_jobs_batch_with_ordering<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ordering: QueueOrdering, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Leases up to batch_size runnable jobs with specified queue ordering preference (QueueOrdering).

Source

fn perform_maintenance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs database maintenance (e.g., VACUUM ANALYZE in Postgres, PRAGMA incremental_vacuum in SQLite).

Source

fn extend_lease<'life0, 'life1, 'async_trait>( &'life0 self, _job_id: Uuid, _worker_id: &'life1 str, _lease_seconds: i64, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Extends the lease lock expiration for an in-flight running job. Returns true if the lease was extended, false if the job lock was lost or reaped.

Source

fn dequeue_and_lease<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queue: &'life1 str, worker_id: &'life2 str, lease_seconds: i64, batch_size: i64, ) -> Pin<Box<dyn Future<Output = Result<Vec<Job>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Dequeues and leases up to batch_size runnable jobs (alias for lease_jobs_batch).

Source

fn complete_job<'life0, 'life1, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Marks a job attempt as completed (alias for mark_succeeded).

Source

fn retry_job<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, next_run_at: DateTime<Utc>, error_code: &'life2 str, error_message: &'life3 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Reschedules a job for retry (alias for reschedule_for_retry).

Source

fn fail_job<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, job_id: Uuid, attempt_id: Uuid, worker_id: &'life1 str, latency_ms: i32, reason_code: &'life2 str, error_code: &'life3 str, error_message: &'life4 str, attempt_no: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Moves a job to DLQ on failure (alias for mark_dlq).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§