Show running jobs in admin header

This commit is contained in:
hbrain 2026-05-25 22:52:59 +02:00
parent 9b29203929
commit 24a773939e
3 changed files with 52 additions and 3 deletions

27
job_status.php Normal file
View file

@ -0,0 +1,27 @@
<?php
require __DIR__ . '/auth.php';
mvlog_require_login();
$config = require __DIR__ . '/config.php';
header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
$jobs = [];
$dirs = glob($config['uploads_dir'] . '/*', GLOB_ONLYDIR) ?: [];
foreach ($dirs as $dir) {
$name = basename($dir);
$stateFile = $dir . '/.movmaker-state.json';
$lockDir = $dir . '/.movmaker-lock';
$state = is_file($stateFile) ? json_decode((string)file_get_contents($stateFile), true) : [];
$status = is_array($state) ? (string)($state['status'] ?? '') : '';
$locked = is_dir($lockDir);
if ($locked || in_array($status, ['processing', 'stale'], true)) {
$started = '';
if (is_file($lockDir . '/started_at')) $started = trim((string)file_get_contents($lockDir . '/started_at'));
if ($started === '' && is_array($state)) $started = (string)($state['started_at'] ?? $state['updated_at'] ?? '');
$jobs[] = [
'name' => $name,
'status' => $status ?: ($locked ? 'processing' : 'unknown'),
'started_at' => $started,
];
}
}
echo json_encode(['jobs' => $jobs, 'checked_at' => date('c')], JSON_UNESCAPED_UNICODE);