Update public source
This commit is contained in:
+45
-17
@@ -13,6 +13,13 @@ class RequestLifecycleMiddleware:
|
|||||||
("POST", "/gps-test/stop"),
|
("POST", "/gps-test/stop"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNTRACKED_DURING_SHUTDOWN = {
|
||||||
|
("GET", "/"),
|
||||||
|
("HEAD", "/"),
|
||||||
|
("GET", "/api/status"),
|
||||||
|
("GET", "/api/gps-test"),
|
||||||
|
}
|
||||||
|
|
||||||
STATIC_PREFIXES = (
|
STATIC_PREFIXES = (
|
||||||
"/static/",
|
"/static/",
|
||||||
"/reports/static/",
|
"/reports/static/",
|
||||||
@@ -99,31 +106,52 @@ class RequestLifecycleMiddleware:
|
|||||||
method = environ.get("REQUEST_METHOD", "GET").upper()
|
method = environ.get("REQUEST_METHOD", "GET").upper()
|
||||||
path = environ.get("PATH_INFO", "/")
|
path = environ.get("PATH_INFO", "/")
|
||||||
|
|
||||||
|
track_request = True
|
||||||
|
|
||||||
with self._condition:
|
with self._condition:
|
||||||
|
|
||||||
if (
|
if self._shutdown_requested:
|
||||||
self._shutdown_requested
|
|
||||||
and not self._is_allowed_during_shutdown(
|
if not self._is_allowed_during_shutdown(
|
||||||
method,
|
method,
|
||||||
path
|
path
|
||||||
)
|
):
|
||||||
):
|
|
||||||
|
|
||||||
body = b"Application is shutting down.\n"
|
body = b"Application is shutting down.\n"
|
||||||
|
|
||||||
start_response(
|
start_response(
|
||||||
"503 Service Unavailable",
|
"503 Service Unavailable",
|
||||||
[
|
[
|
||||||
("Content-Type", "text/plain; charset=utf-8"),
|
("Content-Type", "text/plain; charset=utf-8"),
|
||||||
("Content-Length", str(len(body))),
|
("Content-Length", str(len(body))),
|
||||||
("Retry-After", "5"),
|
("Retry-After", "5"),
|
||||||
("Cache-Control", "no-store"),
|
("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:
|
try:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user