Track progress, save checkpoints, and send structured logs from within tasks.
Copy
Ask AI
import upnext@worker.task(retries=3, timeout=60.0)async def process_data(items: list[str]) -> dict: ctx = upnext.get_current_context() for i, item in enumerate(items): ctx.set_progress((i + 1) / len(items) * 100, f"Processing {item}") ctx.checkpoint({"last_index": i}) ctx.send_log("info", "All items processed") return {"processed": len(items)}
The Context gives you access to the current job’s execution state. Use it to report progress, save recovery checkpoints, and send structured logs to the dashboard.
Check is_cancelled in long-running tasks to exit early when a cancellation is requested:
Copy
Ask AI
@worker.task(timeout=300.0)async def long_running_task(): ctx = upnext.get_current_context() for i in range(1000): if ctx.is_cancelled: return {"stopped_at": i} await do_work(i)
All context methods (set_progress, checkpoint, send_log) work in both async and sync tasks. They detect the execution environment automatically — no special handling needed.