Skip to main content

Crate duroxide_pg_opt

Crate duroxide_pg_opt 

Source
Expand description

§Duroxide PostgreSQL Provider

A PostgreSQL-based provider implementation for Duroxide, a durable task orchestration framework for Rust.

§Usage

use duroxide_pg_opt::PostgresProvider;
use duroxide::runtime::Runtime;
use std::sync::Arc;

// Create a provider with the database URL
let provider = PostgresProvider::new("postgres://user:password@localhost:5432/mydb").await?;

// Use with the Duroxide runtime
// let runtime = Runtime::start_with_store(Arc::new(provider), activity_registry, orchestration_registry).await;

§Custom Schema

To isolate data in a specific PostgreSQL schema (useful for multi-tenant deployments):

use duroxide_pg_opt::PostgresProvider;

let provider = PostgresProvider::new_with_schema(
    "postgres://user:password@localhost:5432/mydb",
    Some("my_schema"),
).await?;

§Configuration

Environment VariableDescriptionDefault
DUROXIDE_PG_POOL_MAXMaximum connection pool size10

§Long-Polling

The provider supports long-polling via PostgreSQL LISTEN/NOTIFY to reduce idle query load:

use duroxide_pg_opt::{PostgresProvider, LongPollConfig};
use std::time::Duration;

let config = LongPollConfig {
    enabled: true,
    notifier_poll_interval: Duration::from_secs(60),
    timer_grace_period: Duration::from_millis(100),
};

let provider = PostgresProvider::new_with_options(
    "postgres://user:password@localhost:5432/mydb",
    Some("my_schema"),
    config,
).await?;

§Features

  • Automatic schema migration on startup
  • Connection pooling via sqlx
  • Custom schema support for multi-tenant isolation
  • Long-polling via LISTEN/NOTIFY for reduced database load
  • Full implementation of the Duroxide Provider and ProviderAdmin traits

§Fault Injection (Testing)

For testing resilience scenarios, enable the test-fault-injection feature:

[dev-dependencies]
duroxide-pg = { version = "0.1", features = ["test-fault-injection"] }

Re-exports§

pub use fault_injection::FaultInjector;
pub use notifier::LongPollConfig;
pub use provider::PostgresProvider;

Modules§

db_metrics
Database metrics instrumentation module.
fault_injection
Database Metrics (Instrumentation)
migrations
notifier
Long-polling notifier for PostgreSQL provider.
provider

Macros§

instrument_db_call
Macro for convenient instrumentation of a database call block. Zero-cost when db-metrics feature is disabled.