Skip to content

Commit 735ff53

Browse files
authored
Merge pull request #46 from taskbadger/sk/procrastinate
Add Procrastinate integration
2 parents cc93e1d + 2c52537 commit 735ff53

17 files changed

Lines changed: 3163 additions & 112 deletions

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,60 @@ taskbadger.init(
4141
$ export TASKBADGER_API_KEY=***
4242
$ taskbadger run "nightly-backup" -- ./backup.sh
4343
```
44+
45+
### Procrastinate Integration
46+
47+
The SDK includes optional support for the [Procrastinate](https://procrastinate.readthedocs.io/) task queue.
48+
49+
Install with the extra:
50+
51+
```bash
52+
pip install 'taskbadger[procrastinate]'
53+
```
54+
55+
Opt a single task into tracking with the `track` decorator:
56+
57+
```python
58+
import procrastinate
59+
from taskbadger.procrastinate import track, current_task
60+
61+
app = procrastinate.App(connector=...)
62+
63+
@track
64+
@app.task(queue="default")
65+
async def add(a, b):
66+
return a + b
67+
68+
@track(name="report", value_max=100, tags={"env": "prod"})
69+
@app.task
70+
async def report(rows):
71+
tb = current_task()
72+
for i, row in enumerate(rows):
73+
await process(row)
74+
if i % 10 == 0:
75+
tb.update(value=i)
76+
```
77+
78+
To auto-track every task on an App, register the system integration:
79+
80+
```python
81+
import taskbadger
82+
from taskbadger.systems.procrastinate import ProcrastinateSystemIntegration
83+
84+
taskbadger.init(
85+
token="***",
86+
systems=[ProcrastinateSystemIntegration(
87+
app=app,
88+
auto_track_tasks=True,
89+
includes=[r"myapp\..*"],
90+
excludes=[r"myapp\.cleanup\..*"],
91+
record_task_args=True,
92+
)],
93+
)
94+
```
95+
96+
#### Known limitations
97+
98+
- **`task.configure(...).defer(...)` is not tracked.** Procrastinate's `configure()` returns a separate `JobDeferrer` whose methods bypass our wrapper. Use `task.defer(...)` directly for tracked deferrals. Tasks deferred via `configure().defer()` will run normally but will not appear in TaskBadger.
99+
- **`task.batch_defer*` is not tracked.** Same reason as `configure().defer()`.
100+
- **Tasks added via `app.add_tasks_from(blueprint)` after `ProcrastinateSystemIntegration` is constructed are not auto-instrumented.** Construct the integration after all blueprints are registered, or apply `@track` to those tasks explicitly.

0 commit comments

Comments
 (0)