diff options
| author | Ben Sima <ben@bensima.com> | 2025-11-22 09:32:06 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-11-22 09:32:06 -0500 |
| commit | d67fa88b8eec1a7514209e84ee5bc3a253cbe8ed (patch) | |
| tree | b1a0555e1020d1c171339edc3cc1cb2007980b98 /Biz/PodcastItLater/Core.py | |
| parent | 820f0a03c5df1359f08ece9ad9d7383b91527608 (diff) | |
Fix: Type checking errors in Web.py and Core.py
Diffstat (limited to 'Biz/PodcastItLater/Core.py')
| -rw-r--r-- | Biz/PodcastItLater/Core.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 @@ -879,6 +879,31 @@ class Database: # noqa: PLR0904 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, ) -> list[dict[str, Any]]: |
