Issue
The video upload watcher system encountered three critical technical issues:
- Priority Queue Comparison Failure: The system crashed when attempting to compare
VideoPairobjects in the priority queue due to a missing comparison method, halting upload processing entirely. - Stuck Exponential Backoff: The retry mechanism for YouTube API quota errors consistently deferred retries for 300 seconds, failing to escalate delays exponentially (e.g., 300s → 900s → 3600s).
- Insufficient Timeout for Long Videos: High-resolution videos (15+ minutes) repeatedly hit a 120-minute timeout threshold before rendering completed, causing unnecessary failures.
Culprit
- Priority Queue Failure: The
VideoPairdataclass lacked a comparison method (__lt__), causing Python’sheapqmodule to fail when comparing objects with identical priority tuples. - Backoff Calculation Logic: The retry counter was scoped per-video-pair, resetting independently for each upload attempt. This resulted in all quota errors triggering the initial 300-second delay, as each pair’s retry count remained at zero.
- Timeout Configuration: The hardcoded 120-minute timeout was insufficient for long rendering tasks, which could exceed 7-8 hours for complex, high-resolution videos.
Solution
- Dataclass Comparison: Implemented a custom
__lt__method in theVideoPairclass to ensure proper comparison logic using the existing sort key, enabling stable heap operations. - Global Quota Backoff: Introduced a global retry counter for quota errors to ensure exponential backoff progression, while preserving per-pair counters for other error types. Added logic to reset the global counter upon reaching maximum retries.
- Extended Timeout Threshold: Increased the timeout limit from 120 minutes to 8 hours to accommodate extended rendering times for high-resolution videos.
Result: The system now correctly handles object comparisons in priority queues, implements true exponential backoff for quota errors, and supports long rendering tasks without premature timeouts.