pgqrs
pgqrs is a postgres-native, library-only durable execution engine.
Written in Rust. Built for Postgres. Also supports SQLite and Turso.
What is Durable Execution?
A durable execution engine ensures workflows resume from application crashes or pauses. Each step executes exactly once. State persists in the database. Processes resume from the last completed step.
Key Properties
- Postgres-native: Leverages SKIP LOCKED, ACID transactions
- Library-only: Runs in-process with your application
- Multi-backend: Postgres (production), SQLite/Turso (testing and embedded)
- Type-safe: Rust core with idiomatic Python bindings
- Transaction-safe: Exactly-once step execution within database transactions
Example
Producer
use Producer;
use Value;
/// Enqueue a payload to the queue
async
Consumer
use ;
use Duration;
/// Poll for jobs from the queue and print them as they arrive
async
Quickstart
Add the library
[]
= "0.15.2"
Start a Postgres DB or get the DSN of an existing db.
You'll need a PostgreSQL database to use pgqrs. Here are your options:
Option 1: Using Docker (Recommended for development)
# Start a PostgreSQL container
# Your DSN will be:
# postgresql://postgres:postgres@localhost:5432/postgres
Option 2: Using an existing PostgreSQL database
Get your database connection string (DSN) in this format:
postgresql://username:password@hostname:port/database
Option 3: Using a cloud PostgreSQL service
- AWS RDS: Get the connection string from the RDS console
- Google Cloud SQL: Get the connection string from the Cloud Console
- Azure Database: Get the connection string from the Azure portal
- Heroku Postgres: Use the
DATABASE_URLfrom your Heroku config
Configure pgqrs
pgqrs can load configuration from environment variables or a pgqrs.yaml file.
Create a pgqrs.yaml file:
dsn: "postgresql://postgres:postgres@localhost:5432/postgres"
Install the pgqrs schema
pgqrs requires a few tables to store metadata. It creates these tables as well as queue tables in the specified schema.
Important: You must create the schema before calling admin.install().
Step 1: Create the schema
Connect to your PostgreSQL database and create the schema:
-- For default 'public' schema (no action needed)
-- For custom schema:
;
Step 2: Install pgqrs
Once you have your database configured and schema created, install and verify the pgqrs schema:
# async
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.