mirror of https://github.com/logos-co/open-law.git
add /health path which checks DB availability
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
63cfa96a07
commit
3ff878b84a
|
@ -1,13 +1,16 @@
|
|||
import os
|
||||
import logging
|
||||
import warnings
|
||||
from uuid import uuid4
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from flask_migrate import Migrate
|
||||
from flask_admin import Admin
|
||||
from sqlalchemy.sql import text
|
||||
from healthcheck import HealthCheck
|
||||
|
||||
from app.logger import log
|
||||
|
||||
|
@ -16,7 +19,6 @@ login_manager = LoginManager()
|
|||
db = SQLAlchemy()
|
||||
migration = Migrate()
|
||||
|
||||
|
||||
def create_app(environment="development"):
|
||||
from config import config
|
||||
from app.views import (
|
||||
|
@ -36,6 +38,18 @@ def create_app(environment="development"):
|
|||
|
||||
# Instantiate app.
|
||||
app = Flask(__name__)
|
||||
app.logger.setLevel(logging.DEBUG)
|
||||
|
||||
# Add healthcheck
|
||||
def db_available():
|
||||
try:
|
||||
db.session.execute(text('SELECT 1'))
|
||||
except Exception as e:
|
||||
return False, str(e)
|
||||
return True, 'database is ok'
|
||||
|
||||
health = HealthCheck(app, '/health')
|
||||
health.add_check(db_available)
|
||||
|
||||
# Set app config.
|
||||
env = os.environ.get("APP_ENV", environment)
|
||||
|
|
|
@ -25,6 +25,11 @@ services:
|
|||
- db
|
||||
ports:
|
||||
- '127.0.0.1:${LOCAL_WEB_PORT:-8000}:${LOCAL_WEB_PORT:-8000}'
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://localhost:${LOCAL_WEB_PORT:-8000}/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
|||
|
||||
APP_ENV=production
|
||||
APP_NAME=Open Law
|
||||
SERVER_NAME=127.0.0.1:8000
|
||||
SERVER_NAME=localhost:8000
|
||||
SECRET_KEY=set_here_secret
|
||||
|
||||
# Database
|
||||
|
|
|
@ -5,7 +5,7 @@ description = ""
|
|||
authors = ["Simple2b https://www.simple2b.net/"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
python = "^3.10"
|
||||
flask = "^2.2.3"
|
||||
flask-migrate = "^4.0.4"
|
||||
flask-mail = "^0.9.1"
|
||||
|
@ -19,6 +19,7 @@ siwe = "^2.2.0"
|
|||
flask-admin = "^1.6.1"
|
||||
wtforms = "^3.0.1"
|
||||
flask-wtf = "^1.1.1"
|
||||
healthcheck = "^1.3.3"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^7.1.1"
|
||||
|
|
Loading…
Reference in New Issue