Close P21 runtime incident journal
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from src.api.trading_runtime import get_trading_runtime_incidents
|
||||
|
||||
|
||||
def main(env=None) -> int:
|
||||
env = os.environ if env is None else env
|
||||
limit = int(env.get("RUNTIME_INCIDENT_LIMIT", "50"))
|
||||
refresh = _get_bool(env, "RUNTIME_INCIDENT_REFRESH", True)
|
||||
output_json = _get_bool(env, "RUNTIME_INCIDENT_OUTPUT_JSON", False)
|
||||
payload = get_trading_runtime_incidents(limit=limit, refresh=refresh)
|
||||
if output_json:
|
||||
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
||||
else:
|
||||
print(f"Runtime incident journal status: {payload.get('status', 'unknown')}")
|
||||
print(f"Persisted: {payload.get('persisted')}")
|
||||
print(f"Incidents: {payload.get('incident_count', 0)}")
|
||||
print(f"Severity counts: {json.dumps(payload.get('severity_counts') or {}, sort_keys=True)}")
|
||||
print(f"Recommended actions: {', '.join(payload.get('recommended_actions') or []) or 'none'}")
|
||||
latest = payload.get("latest_incident") or {}
|
||||
if latest:
|
||||
print(
|
||||
"Latest: "
|
||||
f"{latest.get('severity')} {latest.get('source')} "
|
||||
f"{latest.get('reason')} @ {latest.get('last_seen_ts')}"
|
||||
)
|
||||
if payload.get("warnings"):
|
||||
print(f"Warnings: {', '.join(payload.get('warnings') or [])}")
|
||||
return 0 if payload.get("status") != "unavailable" else 2
|
||||
|
||||
|
||||
def _get_bool(env, key: str, default: bool) -> bool:
|
||||
value = env.get(key)
|
||||
if value is None or value == "":
|
||||
return default
|
||||
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -21,8 +21,13 @@ def main(env=None) -> int:
|
||||
if output_json:
|
||||
print(json.dumps(payload, ensure_ascii=False, sort_keys=True))
|
||||
else:
|
||||
incident_summary = dict(payload.get("incident_summary") or {})
|
||||
print(f"Trading runtime: {payload.get('scheduler_state')} / {payload.get('supervisor_state', 'stopped')}")
|
||||
print(f"Blockers: {', '.join(payload.get('current_blockers') or []) or 'none'}")
|
||||
print(
|
||||
"Incident journal: "
|
||||
f"{incident_summary.get('status', 'idle')} / {incident_summary.get('incident_count', 0)}"
|
||||
)
|
||||
return 0 if not payload.get("current_blockers") else 2
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user