Skip to main content

PostgresBackend

Struct PostgresBackend 

Source
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

Source

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

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 URL
  • queue_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 milliseconds
  • pool_size - Maximum number of connections in the pool

Trait Implementations§

Source§

impl Clone for PostgresBackend

Source§

fn clone(&self) -> PostgresBackend

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
Source§

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,

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,

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,

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,

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,

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,

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,

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,

Get recent events for an activity.
Source§

fn event_stream( &self, ) -> BoxStream<'static, Result<ActivityEvent, StorageError>>

Stream real-time activity events. Read more
Source§

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,

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,

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,

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,

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,

Process scheduled activities that are ready to run. Read more
Source§

fn schedules_natively(&self) -> bool

Whether this backend handles scheduled activities natively in dequeue(). Read more
Source§

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,

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,

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,

Evaluate idempotency rules before enqueueing. Read more
Source§

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,

Retrieve a stored activity result.

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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 = 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Storage for T