#!/usr/bin/env php getAllJobs(), fn($j) => $j['status'] === 'running'); $running = count($activeJobs); if ($running < $config['limits']['max_concurrent_jobs']) { $nextJob = $queue->dequeue(); if ($nextJob) { echo "[" . date('H:i:s') . "] Processing: {$nextJob['queue_id']}\n"; try { $result = $converter->convert([ 'input_file' => $nextJob['input_file'] ?? '', 'output_format' => $nextJob['output_format'] ?? 'mp4', 'preset' => $nextJob['preset'] ?? 'balanced', 'resolution' => $nextJob['resolution'] ?? null, ]); if (isset($result['error'])) { $queue->fail($nextJob['queue_id'], $result['error']); echo "[" . date('H:i:s') . "] Failed: {$result['error']}\n"; } else { $queue->complete($nextJob['queue_id'], $result); echo "[" . date('H:i:s') . "] Started job: {$result['id']}\n"; } } catch (\Throwable $e) { $queue->fail($nextJob['queue_id'], $e->getMessage()); echo "[" . date('H:i:s') . "] Error: {$e->getMessage()}\n"; } } } sleep(2); }