restart.py
1 """Shared gateway restart constants and parsing helpers.""" 2 3 from hermes_cli.config import DEFAULT_CONFIG 4 5 # EX_TEMPFAIL from sysexits.h — used to ask the service manager to restart 6 # the gateway after a graceful drain/reload path completes. 7 GATEWAY_SERVICE_RESTART_EXIT_CODE = 75 8 9 DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUT = float( 10 DEFAULT_CONFIG["agent"]["restart_drain_timeout"] 11 ) 12 13 14 def parse_restart_drain_timeout(raw: object) -> float: 15 """Parse a configured drain timeout, falling back to the shared default.""" 16 try: 17 value = float(raw) if str(raw or "").strip() else DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUT 18 except (TypeError, ValueError): 19 return DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUT 20 return max(0.0, value)