34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
// blade-status-public.php · read-only public endpoint for WTP footer widget (doctrine 14)
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
$hb_path = '/var/www/html/api/blade-tasks/heartbeat.json';
|
|
$online = false; $ago = null; $tasks = null;
|
|
if (file_exists($hb_path)) {
|
|
$hb = @json_decode(@file_get_contents($hb_path), true);
|
|
if ($hb && !empty($hb['ts'])) {
|
|
$ago = time() - strtotime($hb['ts']);
|
|
$online = $ago < 180; // 3 min threshold
|
|
}
|
|
}
|
|
// Task counts (read-only)
|
|
$td = '/var/www/html/api/blade-tasks';
|
|
$p=0; $d=0; $f=0;
|
|
if (is_dir($td)) {
|
|
foreach (glob($td.'/task_*.json') ?: [] as $t) {
|
|
$j = @json_decode(@file_get_contents($t), true);
|
|
if (!$j) continue;
|
|
$s = $j['status'] ?? '';
|
|
if ($s==='pending') $p++;
|
|
elseif ($s==='done') $d++;
|
|
elseif ($s==='failed') $f++;
|
|
}
|
|
}
|
|
echo json_encode([
|
|
'online' => $online,
|
|
'ago_sec' => $ago,
|
|
'label' => $online ? 'live' : ($ago ? 'intermittent' : 'offline'),
|
|
'class' => $online ? 'ok' : ($ago && $ago < 600 ? 'warn' : 'danger'),
|
|
'tasks' => ['pending' => $p, 'done' => $d, 'failed' => $f]
|
|
]);
|