Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ def getRateLimitFromConfig(

STORE_TRANSACTIONAL_EMAILS = "STORE_TRANSACTIONAL_EMAILS" in os.environ

MAINTENANCE_MODE = "MAINTENANCE_MODE" in os.environ

EVENT_WEBHOOK = os.environ.get("EVENT_WEBHOOK", None)

# We want it disabled by default, so only skip if defined
Expand Down
45 changes: 45 additions & 0 deletions maintenance_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from app import config

from flask import Flask, request, jsonify, render_template
from werkzeug.middleware.proxy_fix import ProxyFix


def create_maintenance_app() -> Flask:
"""Minimal Flask app used when MAINTENANCE_MODE is set at startup.
Requires no database connection."""
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_host=1)

@app.route("/health", methods=["GET"])
def healthcheck():
return "success", 200

@app.before_request
def maintenance():
if (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could convert this to an if not and return the jsonify error below and then everything would 503 except these no?

request.path.startswith("/health")
or request.path.startswith("/admin")
or request.path.startswith("/static")
):
return
if request.path.startswith("/api/"):
return (
jsonify(
{"error": "Service is under maintenance, please try again later"}
),
503,
)
return render_template("error/503.html"), 503

@app.context_processor
def inject_stage_and_region():
import arrow

now = arrow.now()
return dict(
YEAR=now.year,
NOW=now,
URL=config.URL,
)

return app
Loading
Loading