From d67fa88b8eec1a7514209e84ee5bc3a253cbe8ed Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 22 Nov 2025 09:32:06 -0500 Subject: Fix: Type checking errors in Web.py and Core.py --- Biz/PodcastItLater/Core.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Biz/PodcastItLater/Core.py') diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py index 2f05db3..3a88f22 100644 --- a/Biz/PodcastItLater/Core.py +++ b/Biz/PodcastItLater/Core.py @@ -878,6 +878,31 @@ class Database: # noqa: PLR0904 row = cursor.fetchone() return dict(row) if row is not None else None + @staticmethod + def get_queue_position(job_id: int) -> int | None: + """Get position of job in pending queue.""" + with Database.get_connection() as conn: + cursor = conn.cursor() + # Get created_at of this job + cursor.execute( + "SELECT created_at FROM queue WHERE id = ?", + (job_id,), + ) + row = cursor.fetchone() + if not row: + return None + created_at = row[0] + + # Count pending items created before or at same time + cursor.execute( + """ + SELECT COUNT(*) FROM queue + WHERE status = 'pending' AND created_at <= ? + """, + (created_at,), + ) + return int(cursor.fetchone()[0]) + @staticmethod def get_user_queue_status( user_id: int, -- cgit v1.2.3