Refactored health checks
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Pünkösd Marcell 2021-08-19 03:12:09 +02:00
parent 7ef991912c
commit 5a5c510fa0
3 changed files with 12 additions and 17 deletions

View File

@ -3,10 +3,10 @@ import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
from healthcheck import HealthCheck
# import stuff
from utils import register_all_error_handlers, storage, health_database_status
from utils import register_all_error_handlers, storage, register_health_checks
# import views
from views import ObjectView
@ -38,8 +38,6 @@ app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# init stuff
storage.init_app(app)
health = HealthCheck()
# register error handlers
register_all_error_handlers(app)
@ -58,8 +56,7 @@ tracing = FlaskTracing(initialize_tracer, True, app)
for view in [ObjectView]:
view.register(app, trailing_slash=False)
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
register_health_checks(app)
# start debugging if needed
if __name__ == "__main__":

View File

@ -2,4 +2,4 @@
from .require_decorators import json_required
from .error_handlers import register_all_error_handlers
from .storage import storage
from .healthchecks import health_database_status
from .healthchecks import register_health_checks

View File

@ -1,15 +1,7 @@
#!/usr/bin/env python3
from utils import storage
"""
Healthchek functions
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "healthchecks"
__version__text__ = "1"
from healthcheck import HealthCheck
from flask import Flask
def health_database_status():
@ -21,3 +13,9 @@ def health_database_status():
output = str(e)
is_database_working = False
return is_database_working, output
def register_health_checks(app: Flask):
health = HealthCheck()
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())