refactor for healthz endpoint (#18)

This commit is contained in:
Brian Rosner 2025-01-12 09:26:45 -07:00 committed by GitHub
commit 40a3e52871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 12 deletions

13
app.json Normal file
View File

@ -0,0 +1,13 @@
{
"healthchecks": {
"api": [
{
"type": "startup",
"name": "api check",
"description": "Checking if the app responds to the /health/ready endpoint",
"path": "/healthz",
"attempts": 3
}
]
}
}

View File

@ -1,7 +1,5 @@
from flask import Flask, g, request
from sqlalchemy import select
from flask import Flask
from . import db as dbm
from .config import Config
from .ext import db
from .v1_api import bp as v1_bp
@ -13,14 +11,6 @@ def create_app():
db.init_app(app)
@app.before_request
def before_request():
if not hasattr(g, "tenant"):
hostname = request.host.split(":")[0]
g.tenant = db.session.scalars(
select(dbm.Tenant).filter_by(hostname=hostname).limit(1)
).first()
@app.teardown_request
def teardown_request(exc):
if exc:
@ -29,4 +19,8 @@ def create_app():
app.register_blueprint(v1_bp)
@app.route("/healthz")
def healthz():
return {"status": "ok"}
return app

View File

@ -1,9 +1,23 @@
from flask import Blueprint
from flask import Blueprint, Flask, g, request
from flask_restful import Api
from sqlalchemy import select
from ..ext import db
from . import db as dbm
from .flights import FlightCollectionResource, FlightResource
bp = Blueprint("api", __name__, url_prefix="/api")
@bp.before_request
def before_request():
if not hasattr(g, "tenant"):
hostname = request.host.split(":")[0]
g.tenant = db.session.scalars(
select(dbm.Tenant).filter_by(hostname=hostname).limit(1)
).first()
api = Api(bp)
api.add_resource(FlightCollectionResource, "/v1/flights")