refactor for healthz endpoint (#18)
This commit is contained in:
commit
40a3e52871
13
app.json
Normal file
13
app.json
Normal 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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
16
teufa/app.py
16
teufa/app.py
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user