How to elegantly use result_backend.set_progress ?? #463
Replies: 1 comment
|
The current task ID is With the current progress API, the backend expects a import asyncio
from taskiq import Context, TaskiqDepends
from taskiq.depends.progress_tracker import TaskProgress, TaskState
@broker.task
async def heavy_task(
key: str, val: str, context: Context = TaskiqDepends(),
) -> str:
for i in range(10):
await asyncio.sleep(1)
await context.broker.result_backend.set_progress(
context.message.task_id,
TaskProgress(
state=TaskState.STARTED,
meta={"percent": (i + 1) * 10},
),
)
return valAlternatively, inject The producer and worker need the same progress-capable result backend. In Sources: Context, ProgressTracker and TaskProgress, Redis progress storage. If you're still using the version from the original post, check its method signature before using the current example. |
Uh oh!
There was an error while loading. Please reload this page.
“
@broker.task
async def heavy_task(key: str, val: str, context: Context = TaskiqDepends()) -> str:
”
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。
All reactions