Skip to content

v0.1.3 - Durable tasks and workflows with just PostgreSQL

Choose a tag to compare

@Kludex Kludex released this 17 Aug 12:21
· 50 commits to main since this release

🐘 Durable tasks and workflows with just PostgreSQL

The first release of pgtask: a task queue, scheduler, and durable workflow runtime that keeps every piece of state in PostgreSQL. No broker, no coordinator, no extension. The engine is Rust; the SDKs are thin clients of one versioned set of database functions.

0.1.0, 0.1.1, and 0.1.2 were release-pipeline casualties and shipped almost nothing. 0.1.3 is the first complete release; use it rather than any of them.

pip install pgtask==0.1.3
import asyncio
import os

from pgtask import Client, Task, TaskRegistry, Worker

tasks = TaskRegistry(queue_name="reports")


@tasks.task("reports.render")
async def render(task: Task, request: dict) -> dict:
    return {"report_id": request["report_id"], "attempt": task.attempt}


async def main() -> None:
    database_url = os.environ["PGTASK_DATABASE_URL"]
    client = await Client.connect(database_url)
    await client.migrate()
    await Worker(database_url, tasks).run()


asyncio.run(main())

🚀 Highlights

  • Enqueue inside your own transaction - pass your connection to Client.enqueue_on and the task commits with your data or not at all. If the transaction rolls back the task never existed, which is the outbox pattern's whole purpose, without the outbox.
  • Leases instead of acknowledgements - a claim stamps the row with a fencing token, and every transition requires it. A worker that stalls, loses its lease, and comes back finds its write matched zero rows, so it cannot overwrite the worker that took over.
  • Durable workflows are database transitions - steps store checkpoints, and a sleep, signal wait, or child-result wait releases the lease entirely. A workflow sleeping six hours costs one row, not a worker slot, and resumes after any restart.
  • Scheduling has no leader - every worker may claim due schedules, and a unique (schedule_id, scheduled_for) key makes duplicate occurrences impossible rather than merely unlikely. Interval and six-field UTC cron, with skip, latest, and bounded catch_up misfire policies.
  • Unknown work is left alone - a worker only receives task names and handler versions it declared, so you can deploy a producer before its consumer and the work waits instead of failing.
  • Least privilege is enforced by the database - producers, workers, observers, and administrators get SECURITY DEFINER functions and security-barrier views, with no direct table grants. A producer physically cannot claim a task or read another payload.
  • Rolling upgrades are a database contract - the schema and every client declare an inclusive storage protocol range, and a worker whose range does not overlap refuses to start with both ranges in the error.
  • OpenTelemetry is part of the engine - trace context travels in task headers, so a worker span is a child of the producer's request, alongside queue, worker, schedule, and admission metrics.
  • One protocol, five languages - Rust, Python, TypeScript, Go, and plain SQL.

📦 What ships

Artifact Contents
Rust crates pgtask, pgtask-core, pgtask-postgres, pgtask-worker, pgtask-otel, pgtask-cli, pgtask-web
Python wheel Stable ABI for CPython 3.10+ on Linux, macOS, and Windows, plus a source distribution
npm @pgtask/client for Node.js 20 or newer
Go module github.com/Kludex/pgtask/sdks/go for Go 1.25 or newer
Container image ghcr.io/kludex/pgtask:0.1.3, multi-architecture, Sigstore signed
Helm chart Signed OCI chart with per-queue worker Deployments, migration Job, probes, and optional autoscaling

PostgreSQL 17 and 18 are both tested.


⚠️ Not ready for production

This is a preview. The engine passes its suite against real PostgreSQL and has never run a production workload. The Rust, Python, SQL, CLI, and telemetry surfaces may change before 1.0; the storage protocol range is the compatibility contract in the meantime.

Delivery is at least once. A handler can finish an external side effect and lose its lease before recording the result, so handlers must be safe to run again.


Documentation: https://kludex.github.io/pgtask/

Full changelog: https://github.com/Kludex/pgtask/commits/v0.1.3