mirror of
https://github.com/myronblair/jarvis
synced 2026-07-28 08:43:00 -05:00
Fix WEB HOST stats never populating (DO server had no monitoring agent installed) and a timezone bug in freshness checks (America/Chicago default timezone + strtotime() on naive UTC MySQL timestamps caused sites/proxmox/ollama facts to never refresh, and could have suppressed the KB intent generator's scheduled runs)
This commit is contained in:
@@ -39,7 +39,7 @@ foreach ($svcNames as $s) {
|
|||||||
|
|
||||||
// Site health from kb_facts
|
// Site health from kb_facts
|
||||||
$siteLabels = [
|
$siteLabels = [
|
||||||
"jarvis" => "jarvis.orbishosting.com:1972",
|
"jarvis" => "jarvis.orbishosting.com",
|
||||||
"tomsjavajive" => "tomsjavajive.com",
|
"tomsjavajive" => "tomsjavajive.com",
|
||||||
"epictravelexp"=> "epictravelexpeditions.com",
|
"epictravelexp"=> "epictravelexpeditions.com",
|
||||||
"parkersling" => "parkerslingshotrentals.com",
|
"parkersling" => "parkerslingshotrentals.com",
|
||||||
|
|||||||
@@ -21,13 +21,18 @@ function collect_all(): array {
|
|||||||
|
|
||||||
// Returns true if a fact category has been updated within $secs seconds.
|
// Returns true if a fact category has been updated within $secs seconds.
|
||||||
// Prevents expensive external calls when data is still fresh.
|
// Prevents expensive external calls when data is still fresh.
|
||||||
|
// Comparison is done entirely in SQL (via NOW()) rather than PHP's time()/strtotime()
|
||||||
|
// — this file's config.php sets date_default_timezone_set('America/Chicago'), which
|
||||||
|
// makes strtotime() misinterpret MySQL's naive (UTC) datetime strings as being in
|
||||||
|
// Chicago time, throwing every freshness check off by the UTC offset (previously
|
||||||
|
// caused "sites" to always look artificially fresh and never actually refresh).
|
||||||
$fresh = function(string $cat, int $secs): bool {
|
$fresh = function(string $cat, int $secs): bool {
|
||||||
$row = JarvisDB::query(
|
$row = JarvisDB::query(
|
||||||
'SELECT updated_at FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1',
|
'SELECT (updated_at > DATE_SUB(NOW(), INTERVAL ? SECOND)) AS is_fresh FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1',
|
||||||
[$cat]
|
[$secs, $cat]
|
||||||
);
|
);
|
||||||
if (empty($row[0]['updated_at'])) return false;
|
if (empty($row)) return false;
|
||||||
return (time() - strtotime($row[0]['updated_at'])) < $secs;
|
return (bool) $row[0]['is_fresh'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,11 +71,14 @@ function normalize_pattern(string $pat): string {
|
|||||||
|
|
||||||
/* ── run guard: skip if ran within last 4 hours ── */
|
/* ── run guard: skip if ran within last 4 hours ── */
|
||||||
/* Set JARVIS_FORCE_RUN=1 (env) or pass --force (argv) to bypass */
|
/* Set JARVIS_FORCE_RUN=1 (env) or pass --force (argv) to bypass */
|
||||||
$lastRun = JarvisDB::single(
|
/* Comparison done in SQL (NOW()) rather than PHP time()/strtotime() — this process's
|
||||||
"SELECT updated_at FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'"
|
date_default_timezone_set('America/Chicago') makes strtotime() misread MySQL's naive
|
||||||
|
(UTC) timestamps as Chicago time, throwing elapsed-time checks off by the UTC offset. */
|
||||||
|
$recentRun = JarvisDB::single(
|
||||||
|
"SELECT (updated_at > DATE_SUB(NOW(), INTERVAL 14400 SECOND)) AS is_recent FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'"
|
||||||
);
|
);
|
||||||
$forceRun = !empty(getenv('JARVIS_FORCE_RUN')) || (isset($argv[1]) && $argv[1] === '--force');
|
$forceRun = !empty(getenv('JARVIS_FORCE_RUN')) || (isset($argv[1]) && $argv[1] === '--force');
|
||||||
if (!$forceRun && $lastRun && (time() - strtotime($lastRun['updated_at'])) < 14400) {
|
if (!$forceRun && $recentRun && $recentRun['is_recent']) {
|
||||||
log_line('Skipping – ran within last 4 hours. Use --force to override.');
|
log_line('Skipping – ran within last 4 hours. Use --force to override.');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user