From 0955cd735126633d126d0fe39faffd5cb6db3bed Mon Sep 17 00:00:00 2001 From: AnyISalIn Date: Mon, 21 Aug 2023 11:51:46 +0800 Subject: [PATCH] feat: add queue index to progress api Signed-off-by: AnyISalIn --- modules/progress.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/progress.py b/modules/progress.py index f405f07fed2..b4ac5690f94 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -71,7 +71,12 @@ def progressapi(req: ProgressRequest): completed = req.id_task in finished_tasks if not active: - return ProgressResponse(active=active, queued=queued, completed=completed, id_live_preview=-1, textinfo="In queue..." if queued else "Waiting...") + textinfo = "Waiting..." + if queued: + sorted_queued = sorted(pending_tasks.keys(), key=lambda x: pending_tasks[x], reverse=True) + queue_index = sorted_queued.index(req.id_task) + textinfo = "In queue: {}/{}".format(queue_index + 1, len(sorted_queued)) + return ProgressResponse(active=active, queued=queued, completed=completed, id_live_preview=-1, textinfo=textinfo) progress = 0