taskiq icon indicating copy to clipboard operation
taskiq copied to clipboard

How to elegantly use result_backend.set_progress ??

Open KitStarLee opened this issue 6 months ago • 1 comments

“ @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.

KitStarLee avatar May 13 '25 08:05 KitStarLee