add job scheduler: sleep between jobs, schedule window, FFmpeg progress parsing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 01:46:41 +01:00
parent 97e60dbfc5
commit 9a19350f7e
2 changed files with 106 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import type { Job, Node, MediaItem, MediaStream } from '../types';
import { predictExtractedFiles } from '../services/ffmpeg';
import { accessSync, constants } from 'node:fs';
import { log, error as logError } from '../lib/log';
import { getSchedulerState, updateSchedulerState } from '../services/scheduler';
const app = new Hono();
@@ -305,4 +306,28 @@ async function runJob(job: Job): Promise<void> {
}
}
// ─── Scheduler ────────────────────────────────────────────────────────────────
// GET /scheduler — current scheduler state
app.get('/scheduler', (c) => {
return c.json(getSchedulerState());
});
// PATCH /scheduler — update scheduler settings
app.patch('/scheduler', async (c) => {
const body = await c.req.json();
updateSchedulerState(body);
return c.json(getSchedulerState());
});
// ─── FFmpeg progress parsing ───────────────────────────────────────────────────
/** Parse FFmpeg stderr line for progress. Returns seconds processed or null. */
export function parseFFmpegProgress(line: string): number | null {
const match = line.match(/time=(\d+):(\d+):(\d+)\.(\d+)/);
if (!match) return null;
const [, h, m, s] = match.map(Number);
return h * 3600 + m * 60 + s;
}
export default app;