Refactored health checks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7ef991912c
commit
5a5c510fa0
@ -3,10 +3,10 @@ import sentry_sdk
|
|||||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
from healthcheck import HealthCheck
|
|
||||||
|
|
||||||
# import stuff
|
# 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
|
# import views
|
||||||
from views import ObjectView
|
from views import ObjectView
|
||||||
@ -38,8 +38,6 @@ app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
|
|||||||
# init stuff
|
# init stuff
|
||||||
storage.init_app(app)
|
storage.init_app(app)
|
||||||
|
|
||||||
health = HealthCheck()
|
|
||||||
|
|
||||||
# register error handlers
|
# register error handlers
|
||||||
register_all_error_handlers(app)
|
register_all_error_handlers(app)
|
||||||
|
|
||||||
@ -58,8 +56,7 @@ tracing = FlaskTracing(initialize_tracer, True, app)
|
|||||||
for view in [ObjectView]:
|
for view in [ObjectView]:
|
||||||
view.register(app, trailing_slash=False)
|
view.register(app, trailing_slash=False)
|
||||||
|
|
||||||
health.add_check(health_database_status)
|
register_health_checks(app)
|
||||||
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
|
||||||
|
|
||||||
# start debugging if needed
|
# start debugging if needed
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
from .require_decorators import json_required
|
from .require_decorators import json_required
|
||||||
from .error_handlers import register_all_error_handlers
|
from .error_handlers import register_all_error_handlers
|
||||||
from .storage import storage
|
from .storage import storage
|
||||||
from .healthchecks import health_database_status
|
from .healthchecks import register_health_checks
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from utils import storage
|
from utils import storage
|
||||||
|
from healthcheck import HealthCheck
|
||||||
"""
|
from flask import Flask
|
||||||
Healthchek functions
|
|
||||||
"""
|
|
||||||
|
|
||||||
__author__ = "@tormakris"
|
|
||||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
|
||||||
__module_name__ = "healthchecks"
|
|
||||||
__version__text__ = "1"
|
|
||||||
|
|
||||||
|
|
||||||
def health_database_status():
|
def health_database_status():
|
||||||
@ -21,3 +13,9 @@ def health_database_status():
|
|||||||
output = str(e)
|
output = str(e)
|
||||||
is_database_working = False
|
is_database_working = False
|
||||||
return is_database_working, output
|
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())
|
||||||
|
Loading…
Reference in New Issue
Block a user