Complete runtime scheduling supervision

This commit is contained in:
Codex
2026-05-08 13:48:44 +08:00
parent ba86e2c1a0
commit 8b3108c296
13 changed files with 715 additions and 57 deletions
+37
View File
@@ -0,0 +1,37 @@
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.services.runtime import get_trading_runtime_service
def main(env=None) -> int:
env = os.environ if env is None else env
output_json = _get_bool(env, "TRADING_RUNTIME_OUTPUT_JSON", False)
run_once = _get_bool(env, "TRADING_RUNTIME_RUN_ONCE", True)
service = get_trading_runtime_service()
payload = service.run_once() if run_once else service.status()
if output_json:
print(json.dumps(payload, ensure_ascii=False, sort_keys=True))
else:
print(f"Trading runtime: {payload.get('scheduler_state')} / {payload.get('supervisor_state', 'stopped')}")
print(f"Blockers: {', '.join(payload.get('current_blockers') or []) or 'none'}")
return 0 if not payload.get("current_blockers") 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())