taskiq
taskiq copied to clipboard
How to elegantly use result_backend.set_progress ??
“ @broker.task async def heavy_task(key: str, val: str, context: Context = TaskiqDepends()) -> str:
for i in range(10):
# Simulate some work
await asyncio.sleep(1)
# Calculate progress
progress = (i + 1) * 10
# Send the progress
# await context.set_progress(progress)
await asyncio.sleep(10)
.....
”
How to obtain the current task_id in the above code ?
Then set the progress using context.broker.result_backend.set_progress().
Because get_ progress returns None by default.