Skip to content

v0.5.0 - Watch task progress and fail fast on values PostgreSQL rejects

Latest

Choose a tag to compare

@Kludex Kludex released this 02 Dec 14:25
f3b567d

🐘 Watch task progress and fail fast on values PostgreSQL rejects

pgtask is a task queue, scheduler, and durable workflow runtime that keeps every piece of state in PostgreSQL. No broker, no coordinator, no extension.

This release lets a client follow a task's state and checkpoints without polling. It also stops a task from repeating a step or a spawn whose value PostgreSQL will never store, and replaces the unmaintained Chrono dependency with time and Croner.

pip install pgtask==0.5.0

👀 Follow a task without polling

  • Watch a task's state and checkpoints from Python (#81). TaskHandle.watch() yields a typed TaskUpdate each time the task's state or checkpoints change, and ends after the update in which the task finishes. It is a plain async iterator, so a timeout around anext() does not end it.
  • Wake observers when a worker records a checkpoint (#81). Workers batch checkpoint wakeups and send them in a separate transaction on 64 pgtask_checkpoint_* shards, which keeps NOTIFY off the checkpoint write path. Rust callers get Store::task_changes() and Store::task_checkpoints().
  • Let a producer read one task's checkpoints (#81). Migration 0016 adds pgtask.task_checkpoints(uuid) and grants it wherever pgtask.task_result(uuid) is granted, so a client with the producer role can watch a task without the observer role.

🧱 Fail once when a value can never be stored

  • Stop repeating a step whose value is too large (#82). A step value over 1 MiB was rejected after the step had run, and the failure was retried, so every attempt ran the step again. The task now fails once with checkpoint_too_large, naming the step, the size, and the limit. A value PostgreSQL rejects for another reason, such as one holding \u0000, fails once with checkpoint_rejected.
  • Stop retrying a spawn PostgreSQL rejects (#87). A child whose payload or headers are over their limit fails the spawning task once with child_spawn_rejected. A full queue is still retried.
  • Deliver a result or signal at the 1 MiB limit (#86). PostgreSQL wraps a child result or a signal before it checkpoints it, and that wrapper pushed values in the last bytes below their own limit over the checkpoint limit. A valid child result then failed with result_rejected or exhausted its parent's attempts, and a valid signal could not reach its waiter. Migration 0017 gives checkpoints 1 KiB of room for the wrapper.

🕰️ Replace Chrono with time and Croner

  • Remove the unmaintained Chrono dependency (#80). Timestamps use time::OffsetDateTime with SQLx's native time support, and cron schedules are evaluated by Croner. The cargo-deny exception for Chrono is gone.
  • Read an infinity timestamp without panicking (#80). time's large-dates feature covers the whole PostgreSQL range, so reading a task whose run_at is infinity or past the year 9999 works.
  • Update dependencies with security advisories (#79). The lock moves rustls, rustls-webpki, tokio, url, and ctutils past their advisories, and off the yanked chacha20 release.

⬆️ Upgrading

This release adds migrations 0016 and 0017. Run migrations with the new CLI before replacing workers:

PGTASK_DATABASE_URL="$DATABASE_URL" pgtask migrate

The storage protocol remains unchanged: the database supports 1..=2, and workers require protocol 2. The migrations preserve existing SQL function signatures, so 0.4.0 and 0.5.0 workers can share the migrated database during a rolling upgrade. TaskHandle.watch() needs migration 0016.

Cron expressions: three spellings that the old parser accepted are now refused. A stored schedule that uses one stops creating tasks: each time it is due, the worker logs a warning and moves it one minute forward. No other schedule runs at a different time.

Spelling Example Write instead
A full day or month name, tues, or thurs 0 0 9 * * monday 0 0 9 * * mon
A wildcard inside a list 0 0 1,* * * * 0 0 * * * *
A space inside a field 1, 0 0 * * * 1,0 0 * * * *

Check stored cron expressions has a query that finds the affected schedules before you upgrade.

Rust API: public types that carried chrono::DateTime<Utc> now carry time::OffsetDateTime. A few timestamp spellings that Chrono parsed, such as an offset without a colon (+0000), are rejected.

Python exception handling: task.step() raises NonRetryableError when its value is over 1 MiB or PostgreSQL rejects it, and task.spawn() does when PostgreSQL rejects the child's values. Both used to raise a retryable RuntimeError.

Error readers: a task's error can now have the types checkpoint_too_large, checkpoint_rejected, and child_spawn_rejected. A Python task records them as a handler_error with "retryable": false.

Checkpoint size: a step value is still limited to 1 MiB, which pgtask.commit_checkpoint now enforces itself. A stored checkpoint can be up to 1 KiB larger when PostgreSQL wraps a result or a signal.


📦 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.5.0, multi-architecture, Sigstore signed
Helm chart Signed OCI chart with per-queue worker Deployments, migration Job, probes, and optional autoscaling

PostgreSQL 16, 17, and 18 are tested.

The Rust, Python, SQL, CLI, and telemetry surfaces may change before 1.0; the storage protocol range is the compatibility contract in the meantime.

Thanks to @Trollgeir for the checkpoint notifications behind watch(), the Chrono replacement, and the dependency updates.


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

Full changelog: v0.4.0...v0.5.0