summaryrefslogtreecommitdiffhomepage
path: root/app/storage.py
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-30 21:37:56 +0900
committerAdam Malczewski <[email protected]>2026-05-30 21:37:56 +0900
commit8e8c64b6dafb8514768f4e801f16eb1a25726d44 (patch)
tree9d8708edfccb5120b82f1be334f1c24b6114387f /app/storage.py
parentcf2a0d5777a28484d518c551cf6a412e54332400 (diff)
downloadyoutube-transcriber-main.tar.gz
youtube-transcriber-main.zip
Make failed transcripts retryable after cooldownHEADmain
Failed queue entries were cached permanently, so a video that failed because subtitles weren't generated yet would never be re-fetched. Add requeue_failed() to reset failed entries to pending, and retry any failed entry once its (120s) cooldown has elapsed.
Diffstat (limited to 'app/storage.py')
-rw-r--r--app/storage.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/storage.py b/app/storage.py
index 2e991d3..d53d860 100644
--- a/app/storage.py
+++ b/app/storage.py
@@ -140,6 +140,23 @@ class TranscriptStore:
)
await self._db.commit()
+ async def requeue_failed(self, video_id: str) -> dict:
+ """Reset a failed queue entry back to pending so it will be retried.
+
+ Assigns a fresh delay and clears the previous error. Returns the entry.
+ """
+ delay = random.uniform(30.0, 60.0)
+ now = datetime.utcnow().isoformat()
+ await self._db.execute(
+ """UPDATE queue
+ SET status = 'pending', assigned_delay = ?, error = NULL,
+ error_type = NULL, updated_at = ?, started_at = NULL
+ WHERE video_id = ? AND status = 'failed'""",
+ (delay, now, video_id),
+ )
+ await self._db.commit()
+ return await self.get_queue_entry(video_id)
+
async def get_position_and_estimate(self, video_id: str) -> dict | None:
"""Return queue position (1-indexed) and estimated wait seconds for a video."""
entry = await self.get_queue_entry(video_id)