1111- ``GET /env`` - selected environment variables (``show.env.variables``) and
1212 selected configuration parameters (``show.application.properties``) -
1313 opt-in lists, so secrets are never dumped wholesale (engine parity).
14- - ``GET /health`` - runs the health- check functions listed in
14+ - ``GET /health`` - runs the health check functions listed in
1515 ``mandatory.health.dependencies`` / ``optional.health.dependencies``.
1616 All mandatory up -> ``UP`` (HTTP 200); any mandatory down -> ``DOWN``
1717 (HTTP 400, engine parity). The outcome feeds the liveness state.
1818- ``GET /livenessprobe`` - ``OK`` (text) while the last health outcome is
1919 good, else HTTP 400 ``Unhealthy. Please check '/health' endpoint.``
2020
21- A health- check function is a normal registered function (usually private)
21+ A health check function is a normal registered function (usually private)
2222speaking the engines' interface contract - called through the same event bus
2323that serves PostOffice, first with header ``type=info`` (an advisory identity
2424map merged into its dependency entry), then with ``type=health`` (a status
@@ -71,9 +71,11 @@ def app_origin() -> str:
7171 """Unique instance id, minted once per process (the Java reference
7272 engine's format: UTC yyyyMMdd date prefix + 32-hex uuid)."""
7373 global _origin
74- if _origin is None :
75- _origin = time .strftime ("%Y%m%d" , time .gmtime ()) + uuid .uuid4 ().hex
76- return _origin
74+ origin = _origin # local narrowing - checkers do not narrow module globals
75+ if origin is None :
76+ origin = time .strftime ("%Y%m%d" , time .gmtime ()) + uuid .uuid4 ().hex
77+ _origin = origin
78+ return origin
7779
7880
7981def elapsed_time (milliseconds : float ) -> str :
@@ -135,9 +137,24 @@ def _app_block(self) -> dict[str, Any]:
135137 return {"name" : self .app_name , "version" : self .app_version ,
136138 "description" : self .description }
137139
138- # aiohttp handlers must be coroutines - async is the framework contract
139- # even when a handler has nothing to await
140- async def handle_info (self , _request : web .Request ) -> web .Response :
140+ async def handle (self , request : web .Request ) -> web .Response :
141+ """The single GET dispatcher (aiohttp handlers must be coroutines):
142+ /health awaits its dependency probes; the rest render synchronously."""
143+ match request .path :
144+ case "/info" :
145+ return self ._info ()
146+ case "/info/routes" :
147+ return self ._routes ()
148+ case "/env" :
149+ return self ._env ()
150+ case "/health" :
151+ return await self ._health ()
152+ case "/livenessprobe" :
153+ return self ._liveness_probe ()
154+ case _: # the router only maps the five paths above here
155+ return web .Response (status = 404 , text = "Not found" )
156+
157+ def _info (self ) -> web .Response :
141158 now = datetime .now (timezone .utc )
142159 return web .json_response ({
143160 "app" : self ._app_block (),
@@ -151,7 +168,7 @@ async def handle_info(self, _request: web.Request) -> web.Response:
151168 "up_time" : elapsed_time ((now - self .start ).total_seconds () * 1000 ),
152169 })
153170
154- async def handle_routes (self , _request : web . Request ) -> web .Response :
171+ def _routes (self ) -> web .Response :
155172 public : dict [str , int ] = {}
156173 private : dict [str , int ] = {}
157174 for route , service in sorted (self .registry .routes ().items ()):
@@ -162,7 +179,7 @@ async def handle_routes(self, _request: web.Request) -> web.Response:
162179 "routing" : {"public" : public , "private" : private },
163180 })
164181
165- async def handle_env (self , _request : web . Request ) -> web .Response :
182+ def _env (self ) -> web .Response :
166183 config = app_config ()
167184 environment = {name : os .environ .get (name , "" )
168185 for name in _as_list (config .get ("show.env.variables" ))}
@@ -173,7 +190,7 @@ async def handle_env(self, _request: web.Request) -> web.Response:
173190 "env" : {"environment" : environment , "properties" : properties },
174191 })
175192
176- async def handle_health (self , _request : web . Request ) -> web .Response :
193+ async def _health (self ) -> web .Response :
177194 dependency : list [dict [str , Any ]] = []
178195 # optional services never affect the overall status (engine semantics)
179196 await self ._check_services (self .optional , required = False , dependency = dependency )
@@ -189,7 +206,7 @@ async def handle_health(self, _request: web.Request) -> web.Response:
189206 result ["name" ] = self .app_name
190207 return web .json_response (result , status = 200 if up else 400 )
191208
192- async def handle_livenessprobe (self , _request : web . Request ) -> web .Response :
209+ def _liveness_probe (self ) -> web .Response :
193210 if self .healthy :
194211 return web .Response (text = "OK" )
195212 return web .Response (status = 400 , text = UNHEALTHY )
0 commit comments