pub struct PostgresBackend { /* private fields */ }Expand description
PostgreSQL-based storage backend for RunnerQ.
This backend provides:
- Permanent persistence - No TTL, records are kept forever
- Multi-node concurrency - Safe dequeue with
FOR UPDATE SKIP LOCKED - Full ACID guarantees - Transactional consistency
- Cross-process events - Uses PostgreSQL LISTEN/NOTIFY for real-time events
Implementations§
Source§impl PostgresBackend
impl PostgresBackend
Sourcepub async fn new(
database_url: &str,
queue_name: &str,
) -> Result<Self, StorageError>
pub async fn new( database_url: &str, queue_name: &str, ) -> Result<Self, StorageError>
Create a new PostgreSQL backend.
§Arguments
database_url- PostgreSQL connection URL (e.g.,postgres://user:pass@host:5432/db)queue_name- Name of the queue (used for namespacing). Must be a valid identifier: starts with letter or underscore, contains only letters, digits, underscores.
§Example
ⓘ
let backend = PostgresBackend::new(
"postgres://postgres:password@localhost:5432/runnerq",
"my_queue"
).await?;Sourcepub async fn with_config(
database_url: &str,
queue_name: &str,
default_lease_ms: i64,
pool_size: u32,
) -> Result<Self, StorageError>
pub async fn with_config( database_url: &str, queue_name: &str, default_lease_ms: i64, pool_size: u32, ) -> Result<Self, StorageError>
Create a new PostgreSQL backend with custom configuration.
§Arguments
database_url- PostgreSQL connection URLqueue_name- Name of the queue. Must be a valid identifier: starts with letter or underscore, contains only letters, digits, underscores.default_lease_ms- Default lease duration in millisecondspool_size- Maximum number of connections in the pool
Trait Implementations§
Source§impl Clone for PostgresBackend
impl Clone for PostgresBackend
Source§fn clone(&self) -> PostgresBackend
fn clone(&self) -> PostgresBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl InspectionStorage for PostgresBackend
impl InspectionStorage for PostgresBackend
Source§fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<QueueStats, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<QueueStats, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get current queue statistics.
Source§fn list_pending<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_pending<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List activities in the pending queue.
Source§fn list_processing<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_processing<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List activities currently being processed.
Source§fn list_scheduled<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_scheduled<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List activities scheduled for future execution.
Source§fn list_completed<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_completed<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List completed activities (recent).
Source§fn list_dead_letter<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<DeadLetterRecord>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_dead_letter<'life0, 'async_trait>(
&'life0 self,
offset: usize,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<DeadLetterRecord>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List activities in the dead letter queue.
Source§fn get_activity<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_activity<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<ActivitySnapshot>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get a specific activity by ID.
Source§fn get_activity_events<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivityEvent>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_activity_events<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ActivityEvent>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get recent events for an activity.
Source§fn event_stream(
&self,
) -> BoxStream<'static, Result<ActivityEvent, StorageError>>
fn event_stream( &self, ) -> BoxStream<'static, Result<ActivityEvent, StorageError>>
Stream real-time activity events. Read more
Source§impl QueueStorage for PostgresBackend
impl QueueStorage for PostgresBackend
Source§fn enqueue<'life0, 'async_trait>(
&'life0 self,
activity: QueuedActivity,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn enqueue<'life0, 'async_trait>(
&'life0 self,
activity: QueuedActivity,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Enqueue an activity for immediate or scheduled execution. Read more
Source§fn dequeue<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
worker_id: &'life1 str,
_timeout: Duration,
activity_types: Option<&'life2 [String]>,
) -> Pin<Box<dyn Future<Output = Result<Option<QueuedActivity>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn dequeue<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
worker_id: &'life1 str,
_timeout: Duration,
activity_types: Option<&'life2 [String]>,
) -> Pin<Box<dyn Future<Output = Result<Option<QueuedActivity>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Try to dequeue one activity for processing. Read more
Source§fn ack_success<'life0, 'life1, 'async_trait>(
&'life0 self,
activity_id: Uuid,
result: Option<Value>,
worker_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn ack_success<'life0, 'life1, 'async_trait>(
&'life0 self,
activity_id: Uuid,
result: Option<Value>,
worker_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Mark a dequeued activity as successfully completed.
Source§fn ack_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
activity_id: Uuid,
failure: FailureKind,
worker_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn ack_failure<'life0, 'life1, 'async_trait>(
&'life0 self,
activity_id: Uuid,
failure: FailureKind,
worker_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Mark a dequeued activity as failed. Read more
Source§fn process_scheduled<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_scheduled<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process scheduled activities that are ready to run. Read more
Source§fn schedules_natively(&self) -> bool
fn schedules_natively(&self) -> bool
Whether this backend handles scheduled activities natively in
dequeue(). Read moreSource§fn requeue_expired<'life0, 'async_trait>(
&'life0 self,
batch_size: usize,
) -> Pin<Box<dyn Future<Output = Result<u64, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn requeue_expired<'life0, 'async_trait>(
&'life0 self,
batch_size: usize,
) -> Pin<Box<dyn Future<Output = Result<u64, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Requeue expired leases back to the ready queue. Read more
Source§fn extend_lease<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
extend_by: Duration,
) -> Pin<Box<dyn Future<Output = Result<bool, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn extend_lease<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
extend_by: Duration,
) -> Pin<Box<dyn Future<Output = Result<bool, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Extend the lease for an activity currently being processed. Read more
Source§fn store_result<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
result: ActivityResult,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn store_result<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
result: ActivityResult,
) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Store the result of a completed activity.
Source§fn check_idempotency<'life0, 'life1, 'async_trait>(
&'life0 self,
activity: &'life1 QueuedActivity,
) -> Pin<Box<dyn Future<Output = Result<Option<Uuid>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check_idempotency<'life0, 'life1, 'async_trait>(
&'life0 self,
activity: &'life1 QueuedActivity,
) -> Pin<Box<dyn Future<Output = Result<Option<Uuid>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Evaluate idempotency rules before enqueueing. Read more
Source§impl ResultStorage for PostgresBackend
impl ResultStorage for PostgresBackend
Source§fn get_result<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<ActivityResult>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_result<'life0, 'async_trait>(
&'life0 self,
activity_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<ActivityResult>, StorageError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieve a stored activity result.
Auto Trait Implementations§
impl Freeze for PostgresBackend
impl !RefUnwindSafe for PostgresBackend
impl Send for PostgresBackend
impl Sync for PostgresBackend
impl Unpin for PostgresBackend
impl UnsafeUnpin for PostgresBackend
impl !UnwindSafe for PostgresBackend
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more