Update public source

This commit is contained in:
2026-11-16 18:59:45 +03:00
parent 37a52f004e
commit 5994d513c8
+45 -17
View File
@@ -13,6 +13,13 @@ class RequestLifecycleMiddleware:
("POST", "/gps-test/stop"),
}
UNTRACKED_DURING_SHUTDOWN = {
("GET", "/"),
("HEAD", "/"),
("GET", "/api/status"),
("GET", "/api/gps-test"),
}
STATIC_PREFIXES = (
"/static/",
"/reports/static/",
@@ -99,31 +106,52 @@ class RequestLifecycleMiddleware:
method = environ.get("REQUEST_METHOD", "GET").upper()
path = environ.get("PATH_INFO", "/")
track_request = True
with self._condition:
if (
self._shutdown_requested
and not self._is_allowed_during_shutdown(
if self._shutdown_requested:
if not self._is_allowed_during_shutdown(
method,
path
)
):
):
body = b"Application is shutting down.\n"
body = b"Application is shutting down.\n"
start_response(
"503 Service Unavailable",
[
("Content-Type", "text/plain; charset=utf-8"),
("Content-Length", str(len(body))),
("Retry-After", "5"),
("Cache-Control", "no-store"),
]
)
start_response(
"503 Service Unavailable",
[
("Content-Type", "text/plain; charset=utf-8"),
("Content-Length", str(len(body))),
("Retry-After", "5"),
("Cache-Control", "no-store"),
]
)
return [body]
return [body]
self._active_requests += 1
if (
(method, path) in self.UNTRACKED_DURING_SHUTDOWN
or (
method in ("GET", "HEAD")
and any(
path.startswith(prefix)
for prefix in self.STATIC_PREFIXES
)
)
):
track_request = False
if track_request:
self._active_requests += 1
if not track_request:
return self.application(
environ,
start_response
)
try: