Prepare rollback-safe legacy migration data contract (#7)
Unraid autoredeploy / Deploy vacatureradar (push) Failing after 20s
Unraid autoredeploy / Deploy vacatureradar (push) Failing after 20s
This commit was merged in pull request #7.
This commit is contained in:
@@ -9,6 +9,30 @@ from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.http import url_has_allowed_host_and_scheme
|
||||
|
||||
from scripts.migration_worker_gate import hold_active
|
||||
|
||||
|
||||
class MigrationMaintenanceMiddleware:
|
||||
"""Block candidate traffic before durable migration activation, including GET writes."""
|
||||
|
||||
def __init__(self, get_response: Callable[[HttpRequest], HttpResponse]) -> None:
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request: HttpRequest) -> HttpResponse:
|
||||
try:
|
||||
held = hold_active()
|
||||
except (OSError, RuntimeError):
|
||||
held = True
|
||||
health = request.method in {"GET", "HEAD"} and request.path_info in {
|
||||
"/health/ready/", "/health/live/",
|
||||
}
|
||||
if held and not health:
|
||||
response = JsonResponse({"error": "migration_maintenance"}, status=503)
|
||||
response["Retry-After"] = "30"
|
||||
response["Cache-Control"] = "no-store"
|
||||
return response
|
||||
return self.get_response(request)
|
||||
|
||||
|
||||
class DemoReadOnlyMiddleware:
|
||||
"""Prevent a shared public demo account from mutating application data."""
|
||||
|
||||
Reference in New Issue
Block a user