Draft
Optimize background scheduler and fix Reddit video download failures#5
Conversation
…cheduler Co-authored-by: enikqi <10384338+enikqi@users.noreply.github.com>
Co-authored-by: enikqi <10384338+enikqi@users.noreply.github.com>
Co-authored-by: enikqi <10384338+enikqi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix yt-dlp Reddit video download failures and performance issues
Optimize background scheduler and fix Reddit video download failures
Nov 4, 2025
Owner
|
@copilot BEFORE running the command, the code you have changed it was the code that was online in yapgrid.com or the one we have uploaded as a project? |
Copilot stopped work on behalf of
enikqi due to an error
November 4, 2025 21:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Application experiencing Reddit video download failures (HTTP 403, JSON parse errors), excessive CPU usage from 30-second scheduler intervals, and memory pressure at 1.8GB/1.9GB limit.
Changes
Media Downloader (
site/lib/media/downloader.ts)--extractor-args "reddit:player_only=False", custom User-Agent, proper cookie file lifecycleBackground Scheduler (
site/background-scheduler.js)API_BASE_URLenv var for API endpointsHealth Monitoring (
site/app/api/health/route.ts)New
/api/healthendpoint returning:Cleanup Service (
site/lib/cleanup.ts)Automatic maintenance:
Resource Limits (
site/ecosystem.config.js)Query Optimization
status,createdUtc,scheduledPublishAtExample Usage
Configuration
CodeQL: 0 vulnerabilities
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
checkpoint.prisma.iofonts.googleapis.com/usr/local/bin/node /home/REDACTED/work/yapgrid/yapgrid/site/node_modules/next/dist/compiled/jest-worker/processChild.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Problem
The application is experiencing multiple issues that need to be fixed:
1. yt-dlp Reddit Video Download Failures
HTTP Error 403: Blockedfrom Reddit's v.redd.it domainFailed to parse JSONerrors when trying to download Reddit videoscookieFile is not definederror)2. Background Job Performance Issues
3. System Performance
Required Fixes
Fix 1: Update and Fix yt-dlp Integration
File:
site/lib/media-downloader.ts(or relevant media download file)Update yt-dlp command with better Reddit support:
--extractor-args "reddit:player_only=False"Fix cookie file handling:
Add retry logic with exponential backoff:
Add better error handling:
Fix 2: Optimize Background Scheduler
File:
site/background-scheduler.jsReduce cron job frequency:
*/30 * * * * *(every 30 seconds) to*/2 * * * *(every 2 minutes)Add process limits:
Improve error handling:
Fix 3: Add Health Check and Monitoring
File:
site/app/api/health/route.ts(create new file)Create a health check endpoint that returns:
Fix 4: Optimize Database Queries
Files: Various API routes that query posts
Add database indexes for frequently queried fields:
posts.statusposts.createdAt(status, createdAt)Optimize queries in:
site/app/api/posts/route.ts- Add limit and proper paginationsite/app/api/posts/process/route.ts- Process in smaller batchesFix 5: Add Automatic Cleanup
File:
site/lib/cleanup.ts(create new file)Create cleanup utility that:
Add cleanup cron job to run every hour in
background-scheduler.jsFix 6: Update PM2 Configuration
File:
site/ecosystem.config.jsAdd memory limits and better configuration:
Fix 7: Improve Logging
Files: All files with MediaDownloader logging
Reduce log verbosity:
Add log rotation:
Testing Requirements
After implementing fixes:
Expected Results
This pull request was created as a result of the following prompt from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.