36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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_watchdog
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
output_json = _get_bool(env, "TRADING_RUNTIME_WATCHDOG_OUTPUT_JSON", False)
|
|
payload = get_trading_runtime_watchdog(run_once=_get_bool(env, "TRADING_RUNTIME_WATCHDOG_RUN_ONCE", True))
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
print(f"Runtime watchdog checked: {payload.get('checked_ts')}")
|
|
print(f"Stalled tasks: {', '.join(payload.get('stalled_task_names') or []) or 'none'}")
|
|
return 0 if not payload.get("stalled_task_count") 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())
|