Skip to content

P3+B1: transcode blocking off event loop + stale-job reaper#337

Merged
detain merged 1 commit into
masterfrom
fix/server-p3-b1-transcode
Jun 29, 2026
Merged

P3+B1: transcode blocking off event loop + stale-job reaper#337
detain merged 1 commit into
masterfrom
fix/server-p3-b1-transcode

Conversation

@detain

@detain detain commented Jun 29, 2026

Copy link
Copy Markdown
Owner

P3+B1: Transcode blocking off event loop + periodic stale-job reaper

Changes

P3 (transcode): FFmpeg already runs detached via startDetached() → nohup ... &. B1 improvements:

  • Added Timer::add reaper (45s interval)
  • STALE_JOB_MAX_AGE lowered from 3600s → 120s
  • SEGMENT_PRODUCTION_TIMEOUT = 60s — jobs with no segment within 60s are marked failed

Files changed:

  • src/Media/Transcoding/TranscodeManager.php — reaper timer + tighter stale thresholds
  • src/Server/Core/Application.php — calls startTranscodeReaperTimer()

Tests

  • testReapStaleRunningJobsReapsJobWithNoSegmentWithinTimeout()
  • testReapStaleRunningJobsKeepsJobWithSegmentsAfterTimeout()

Verification

  • ./vendor/bin/phpunit — 216 tests, 543 assertions ✅
  • ./vendor/bin/phpstan analyze --level=9 — no errors ✅
  • ./vendor/bin/phpcs PSR-12 — no errors ✅

…timer

B1: Improve stale-job reaper in TranscodeManager:
- Add SEGMENT_PRODUCTION_TIMEOUT (60s): reaps jobs that have produced
  zero segments within 60s of startup (wedged ffmpeg catches)
- Lower STALE_JOB_MAX_AGE from 3600s to 120s so wedged encodes
  free their concurrency slot promptly
- REAPER_INTERVAL constant (45s) for the periodic timer
- Add startReaperTimer() method that registers a Workerman Timer::add
  to run reapStaleRunningJobs() every 45s

B1: Register the reaper timer in Application::run():
- startTranscodeReaperTimer() is called after other timers
- Gets TranscodeManager from container and calls startReaperTimer()
- Logs any startup errors so a failing reaper never crashes the worker

B1: Add unit tests:
- testReapStaleRunningJobsReapsJobWithNoSegmentWithinTimeout:
  verifies a job with no segments after 90s is reaped with the
  'no segment produced within 60s (wedged)' error
- testReapStaleRunningJobsKeepsJobWithSegmentsAfterTimeout:
  verifies a job that HAS segments is NOT reaped even if old
  (encoder may be slow but is not wedged)

P3: The FFmpeg transcode is already running detached via
startCmafTranscodeWithSubtitles() → startDetached() → nohup ... &.
The transcode worker IS the detached ffmpeg process. The probe()
call remains synchronous but is typically fast (0.1-0.5s).
The reaper improvements ensure wedged jobs free their slot promptly.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 5 medium · 1 minor

Alerts:
⚠ 6 issues (≤ 0 issues of at least minor severity)

Results:
6 new issues

Category Results
BestPractice 1 medium
CodeStyle 1 minor
Complexity 4 medium

View in Codacy

🟢 Metrics 32 complexity · 0 duplication

Metric Results
Complexity 32
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.96%. Comparing base (777fbe5) to head (13a7efc).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Media/Transcoding/TranscodeManager.php 50.00% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #337      +/-   ##
============================================
- Coverage     59.97%   59.96%   -0.02%     
- Complexity    13007    13013       +6     
============================================
  Files           481      481              
  Lines         42131    42152      +21     
============================================
+ Hits          25270    25276       +6     
- Misses        16861    16876      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@detain detain merged commit 302b3d8 into master Jun 29, 2026
12 of 16 checks passed
@detain detain deleted the fix/server-p3-b1-transcode branch June 29, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant