Skip to content

Add Procrastinate integration#46

Merged
snopoke merged 18 commits into
mainfrom
sk/procrastinate
May 26, 2026
Merged

Add Procrastinate integration#46
snopoke merged 18 commits into
mainfrom
sk/procrastinate

Conversation

@snopoke
Copy link
Copy Markdown
Collaborator

@snopoke snopoke commented May 26, 2026

Summary

Adds first-class TaskBadger tracking for the Procrastinate task queue, paralleling the existing Celery integration.

Public API:

  • taskbadger.procrastinate.track — per-task decorator (bare or parameterized: @track(name=..., value_max=..., tags=..., data=..., record_task_args=...)).
  • taskbadger.procrastinate.current_task() — ContextVar-backed accessor for the running TB task.
  • taskbadger.systems.procrastinate.ProcrastinateSystemIntegration — auto-track all tasks on an App, with includes / excludes regex filters.

Lifecycle:

  • PENDING — created when task.defer(...) / task.defer_async(...) is called. The TB task id is smuggled through Procrastinate's task_kwargs under a reserved key (__taskbadger_task_id__).
  • PROCESSING — set when the worker picks up the job.
  • SUCCESS / ERROR — set when the user function returns or raises (exception is re-raised so Procrastinate's retry logic still runs).

Other notes:

  • Sync and async tasks both supported (inspect.iscoroutinefunction dispatch).
  • pass_context=True works transparently — the wrapper uses *args/**kwargs so the context is forwarded unchanged.
  • procrastinate >= 3.0 is opt-in via the new taskbadger[procrastinate] extra; the top-level taskbadger package never imports Procrastinate.
  • Tests: 17 unit tests in tests/test_procrastinate.py, 13 in tests/test_procrastinate_system_integration.py, 2 real-Postgres integration tests in integration_tests/test_procrastinate.py (gated by PROCRASTINATE_DSN + TASKBADGER_* env vars).

Known limitations (documented in README, candidates for follow-up)

  • task.configure(...).defer(...) is not tracked — Procrastinate's configure() returns a separate JobDeferrer that bypasses our wrapper.
  • task.batch_defer* is not tracked — same reason.
  • Tasks added via app.add_tasks_from(blueprint) after the system integration is constructed are not auto-instrumented; construct the integration after blueprint registration or apply @track to those tasks explicitly.
  • Built-in Procrastinate housekeeping tasks (builtin: / procrastinate.*) are explicitly skipped by track_task.

Design + plan

  • Spec: docs/superpowers/specs/2026-05-25-procrastinate-integration-design.md
  • Plan: docs/superpowers/plans/2026-05-25-procrastinate-integration.md

Test plan

  • Unit suite (134 passing locally; ruff + format clean)
  • Integration tests against real Postgres + TaskBadger API (set PROCRASTINATE_DSN and TASKBADGER_* env vars, then uv run pytest integration_tests/test_procrastinate.py -vs)
  • Manual smoke test with a real Procrastinate app

🤖 Generated with Claude Code

snopoke and others added 16 commits May 25, 2026 14:31
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… docs

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- ProcrastinateSystemIntegration.track_task now refuses task names
  starting with "builtin:" or "procrastinate." so Procrastinate's own
  housekeeping jobs aren't auto-tracked.
- README documents three known limitations: configure().defer(),
  batch_defer*, and post-init add_tasks_from.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@snopoke snopoke marked this pull request as ready for review May 26, 2026 08:57
@snopoke snopoke merged commit 735ff53 into main May 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant