fix: update version to v1.4.2 and improve status reporting in tray
feat: now sends watcher_status via payload to terra-view
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Series 3 Watcher — v1.4.1
|
||||
Series 3 Watcher — v1.4.2
|
||||
|
||||
Environment:
|
||||
- Python 3.8 (Windows 7 compatible)
|
||||
@@ -220,7 +220,7 @@ def scan_latest(
|
||||
|
||||
|
||||
# --- API heartbeat / SFM telemetry helpers ---
|
||||
VERSION = "1.4.1"
|
||||
VERSION = "1.4.2"
|
||||
|
||||
|
||||
def _read_log_tail(log_file: str, n: int = 25) -> Optional[list]:
|
||||
@@ -398,45 +398,25 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
||||
)
|
||||
now_epoch = time.time()
|
||||
|
||||
# Build per-unit status list for the tray
|
||||
# Log detected units to console and log file (info only, no status judgement)
|
||||
unit_list = []
|
||||
worst = "ok" # tracks worst status across all units
|
||||
|
||||
if latest:
|
||||
print("\nDetected Units (within last {} days):".format(MAX_EVENT_AGE_DAYS))
|
||||
for uid in sorted(latest.keys()):
|
||||
info = latest[uid]
|
||||
age_hours = (now_epoch - info["mtime"]) / 3600.0
|
||||
if age_hours > MISSING_HOURS:
|
||||
status, col = "missing", C_MIS
|
||||
elif age_hours > OK_HOURS:
|
||||
status, col = "pending", C_PEN
|
||||
else:
|
||||
status, col = "ok", C_OK
|
||||
|
||||
# escalate worst status
|
||||
if status == "missing":
|
||||
worst = "missing"
|
||||
elif status == "pending" and worst != "missing":
|
||||
worst = "pending"
|
||||
|
||||
unit_list.append({
|
||||
"uid": uid,
|
||||
"status": status,
|
||||
"age_hours": age_hours,
|
||||
"last": fmt_last(info["mtime"]),
|
||||
"fname": info["fname"],
|
||||
})
|
||||
|
||||
line = (
|
||||
"{col}{uid:<8} {status:<8} Age: {age:<7} Last: {last} (File: {fname}){rst}".format(
|
||||
col=col,
|
||||
"{uid:<8} Age: {age:<7} Last: {last} (File: {fname})".format(
|
||||
uid=uid,
|
||||
status=status.capitalize(),
|
||||
age=fmt_age(now_epoch, info["mtime"]),
|
||||
last=fmt_last(info["mtime"]),
|
||||
fname=info["fname"],
|
||||
rst=C_RST,
|
||||
)
|
||||
)
|
||||
print(line)
|
||||
@@ -448,10 +428,9 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
||||
ENABLE_LOGGING,
|
||||
"[info] no recent MLG activity within {} days".format(MAX_EVENT_AGE_DAYS),
|
||||
)
|
||||
worst = "missing"
|
||||
|
||||
# Update shared state for tray
|
||||
state["status"] = worst
|
||||
# Update shared state for tray — status reflects watcher health, not unit ages
|
||||
state["status"] = "running"
|
||||
state["units"] = unit_list
|
||||
state["last_scan"] = datetime.now()
|
||||
state["last_error"] = None
|
||||
@@ -463,12 +442,19 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
||||
if now_ts - last_api_ts >= interval:
|
||||
hb_payload = build_sfm_payload(latest, cfg)
|
||||
hb_payload["version"] = VERSION
|
||||
hb_payload["watcher_status"] = state.get("status", "unknown")
|
||||
hb_payload["log_tail"] = _read_log_tail(cfg.get("LOG_FILE", ""), 25)
|
||||
response = send_api_payload(hb_payload, cfg.get("API_URL", ""))
|
||||
last_api_ts = now_ts
|
||||
# Surface update signal to tray
|
||||
if response and response.get("update_available"):
|
||||
state["update_available"] = True
|
||||
if response is not None:
|
||||
state["api_status"] = "ok"
|
||||
state["last_api"] = datetime.now()
|
||||
if response.get("update_available"):
|
||||
state["update_available"] = True
|
||||
else:
|
||||
state["api_status"] = "fail"
|
||||
else:
|
||||
state["api_status"] = "disabled"
|
||||
|
||||
except Exception as e:
|
||||
err = "[loop-error] {}".format(e)
|
||||
|
||||
Reference in New Issue
Block a user