PostgreSQL-native durable tasks and workflows
Actively maintained. Last release 8 weeks ago, commits in 7 of the last 26 weeks. A safe choice.
pip install pgtaskPostgreSQL-native durable tasks and workflows
Actively maintained. Last release 8 weeks ago, commits in 7 of the last 26 weeks. A safe choice.
pip install pgtaskDurable tasks and workflows that live entirely in PostgreSQL.
There is no broker, no coordinator, and no extension to install. If your database is up, your queue is up.
[!WARNING]
pgtaskis under active development. It is not ready for production use.
pip install pgtask
A registry maps a task name to the function that runs it. A worker claims work for that queue, one lease at a time, so a worker that dies hands its tasks back instead of taking them with it.
from __future__ import annotations
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, payload: dict) -> dict:
return {"report_id": payload["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())
Delivery is at least once, so write handlers that are safe to run again.
from __future__ import annotations
import asyncio
import os
from pgtask import Client, EnqueueRequest
async def main() -> None:
client = await Client.connect(os.environ["PGTASK_DATABASE_URL"])
handle = await client.enqueue(
EnqueueRequest("reports.render", {"report_id": "report-123"}, queue_name="reports")
)
print(await handle.result(timeout=30.0))
asyncio.run(main())
This is the reason to keep the queue in the database. Pass your own connection and the task commits with your data or not at all. Roll back and the task never existed, which is what an outbox table is usually for.
async with connection.transaction():
await connection.execute("INSERT INTO reports (id) VALUES (%s)", ("report-123",))
await Client.enqueue_on(connection, request)
connection is your psycopg connection, not one of ours.
kludex.github.io/pgtask covers workers, durable execution, signals, cancellation, scheduling, and OpenTelemetry propagation.
Use instead of pgtask: tools that do the same job, closest first.
Compare with pgqueuer →Compare with procrastinate →Compare with absurd-sdk →Compare all 4 →
PostgreSQL-backed background job and task queue for Python.
OpenSSF Scorecard
not evaluated
Postgres-based distributed task processing library
Python SDK for Absurd - PostgreSQL-based durable task execution
Ultra-lightweight durable execution in Python
Distributed task queue with full async support
a little task queue