This is the official Python SDK for Task Badger.
For full documentation go to https://docs.taskbadger.net/python/.
pip install taskbadgerTo use the taskbadger command-line tool, install the cli extra:
pip install 'taskbadger[cli]'import taskbadger
from taskbadger.systems import CelerySystemIntegration
taskbadger.init(
token="***",
systems=[CelerySystemIntegration()],
tags={"environment": "production"}
)$ export TASKBADGER_API_KEY=***
$ taskbadger run "nightly-backup" -- ./backup.shThe SDK includes optional support for the Procrastinate task queue.
Install with the extra:
pip install 'taskbadger[procrastinate]'Opt a single task into tracking with the track decorator:
import procrastinate
from taskbadger.procrastinate import track, current_task
app = procrastinate.App(connector=...)
@track
@app.task(queue="default")
async def add(a, b):
return a + b
@track(name="report", value_max=100, tags={"env": "prod"})
@app.task
async def report(rows):
tb = current_task()
for i, row in enumerate(rows):
await process(row)
if i % 10 == 0:
tb.update(value=i)To auto-track every task on an App, register the system integration:
import taskbadger
from taskbadger.systems.procrastinate import ProcrastinateSystemIntegration
taskbadger.init(
token="***",
systems=[ProcrastinateSystemIntegration(
app=app,
auto_track_tasks=True,
includes=[r"myapp\..*"],
excludes=[r"myapp\.cleanup\..*"],
record_task_args=True,
)],
)task.configure(...).defer(...)is not tracked. Procrastinate'sconfigure()returns a separateJobDeferrerwhose methods bypass our wrapper. Usetask.defer(...)directly for tracked deferrals. Tasks deferred viaconfigure().defer()will run normally but will not appear in TaskBadger.task.batch_defer*is not tracked. Same reason asconfigure().defer().- Tasks added via
app.add_tasks_from(blueprint)afterProcrastinateSystemIntegrationis constructed are not auto-instrumented. Construct the integration after all blueprints are registered, or apply@trackto those tasks explicitly.