diff --git a/api/tasks-feed.php b/api/tasks-feed.php new file mode 100644 index 000000000..94abae0eb --- /dev/null +++ b/api/tasks-feed.php @@ -0,0 +1,87 @@ + $name, + 'title' => $title, + 'status' => $status, + 'mtime' => date('c', $mtime), + 'age_min' => $age_min, + 'age_human' => $age_min < 60 ? "${age_min}min" : floor($age_min/60) . 'h', + 'size_bytes' => $size, + 'preview' => substr($content, 0, 160) + ]; +} + +// Build 24h timeline (count per hour bucket) +$timeline = array_fill(0, 24, ['hour' => 0, 'done' => 0, 'failed' => 0, 'pending' => 0]); +$now_h = (int)date('H'); +foreach ($timeline as $i => &$t) { + $t['hour'] = ($now_h - 23 + $i + 24) % 24; +} +unset($t); + +$all_jobs = glob('/tmp/wevia-job-*.log'); +foreach ($all_jobs as $f) { + $mtime = filemtime($f); + if (time() - $mtime > 86400) continue; // last 24h only + $hour_offset = (int)floor((time() - $mtime) / 3600); + if ($hour_offset >= 24) continue; + $idx = 23 - $hour_offset; + $content = @file_get_contents($f); + if (preg_match('/elapsed=|DONE|OK /', $content)) $timeline[$idx]['done']++; + elseif (preg_match('/ERROR|FAIL|denied/', $content)) $timeline[$idx]['failed']++; + else $timeline[$idx]['pending']++; +} + +echo json_encode([ + 'ok' => true, + 'ts' => date('c'), + 'summary' => [ + 'total' => count($tasks), + 'done' => $done, + 'failed' => $failed, + 'pending' => $pending + ], + 'tasks' => $tasks, + 'timeline_24h' => $timeline +], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); \ No newline at end of file diff --git a/api/web-ia-health-cached.php b/api/web-ia-health-cached.php new file mode 100644 index 000000000..4faa6c422 --- /dev/null +++ b/api/web-ia-health-cached.php @@ -0,0 +1,45 @@ + true, + CURLOPT_TIMEOUT => 6, + CURLOPT_HTTPHEADER => ['Host: weval-consulting.com'] +]); +$resp = curl_exec($ch); +curl_close($ch); + +if ($resp && strlen($resp) > 50) { + // Cache it + @file_put_contents($cache_file, $resp); + echo $resp; +} else { + // Fallback: serve stale cache if exists + if (file_exists($cache_file)) { + echo file_get_contents($cache_file); + } else { + // Hard fallback minimal + echo json_encode([ + 'ok' => false, + 'ts' => date('c'), + 'error' => 'API timeout, no cache available', + 'sections' => [ + 'blade' => ['online' => false, 'status_label' => 'LOADING', 'color' => 'orange'], + 'cdp' => ['running' => 0, 'total' => 8], + 'tasks' => ['done' => 0, 'stale' => 0] + ] + ]); + } +} \ No newline at end of file diff --git a/web-ia-health.html b/web-ia-health.html index 4d62df6e7..323f881de 100644 --- a/web-ia-health.html +++ b/web-ia-health.html @@ -141,7 +141,7 @@ function toast(msg, err){ async function load(){ GRID.classList.add("loading"); try{ - const r = await fetch("/api/web-ia-health.php?_="+Date.now(),{cache:"no-store"}); + const r = await fetch("/api/web-ia-health-cached.php?_="+Date.now(),{cache:"no-store"}); const d = await r.json(); render(d); }catch(e){ @@ -463,5 +463,100 @@ function doAsk(){ load(); setInterval(load, 30000); +