Show a launched job's progress, stop a refused rerun from overwriting the live record, and label deployed containers so Unraid owns them
This commit is contained in:
@@ -53,6 +53,40 @@
|
||||
header('Content-Type: application/json');
|
||||
require_once dirname(__DIR__) . '/include/scheduler.php';
|
||||
|
||||
// ?id=<Category/name.sh> — one job, including jobs that are not on the schedule.
|
||||
//
|
||||
// The loop below only knows about scheduled jobs, so a job like Partnership/partnership_onboard.sh
|
||||
// — launched on demand, never cronned — was invisible to every status caller even though
|
||||
// run_job.sh writes it a stat file like any other. The UI had nothing to poll, which is why
|
||||
// pressing Onboard produced no visible change for the minutes it then ran.
|
||||
if (isset($_GET['id'])) {
|
||||
$id = trim($_GET['id']);
|
||||
if (!preg_match('/^[a-zA-Z0-9_.\/\-]+\.sh$/', $id) || str_contains($id, '..')) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Invalid job id']);
|
||||
exit;
|
||||
}
|
||||
$statFile = vv_job_stat_path($id);
|
||||
if (!file_exists($statFile)) {
|
||||
echo json_encode(['ok' => true, 'id' => $id, 'status' => 'never_run']);
|
||||
exit;
|
||||
}
|
||||
$stat = json_decode(@file_get_contents($statFile) ?: '{}', true) ?: [];
|
||||
$status = $stat['status'] ?? 'unknown';
|
||||
// Same liveness rule as the loop: a dead runner reports error, never "still running".
|
||||
if ($status === 'running' && !empty($stat['pid']) && !file_exists("/proc/{$stat['pid']}")) {
|
||||
$status = 'error';
|
||||
}
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'id' => $id,
|
||||
'status' => $status,
|
||||
'start' => $stat['start'] ?? null,
|
||||
'end' => $stat['end'] ?? null,
|
||||
'exit' => $stat['exit'] ?? null,
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach (array_keys(vv_schedule_load()) as $id) {
|
||||
$statFile = vv_job_stat_path($id);
|
||||
|
||||
Reference in New Issue
Block a user