This commit is contained in:
		@@ -5,12 +5,13 @@ from flask_restful import Api
 | 
			
		||||
import sentry_sdk
 | 
			
		||||
from sentry_sdk.integrations.flask import FlaskIntegration
 | 
			
		||||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
 | 
			
		||||
 | 
			
		||||
from healthcheck import HealthCheck
 | 
			
		||||
 | 
			
		||||
from config import *
 | 
			
		||||
from db import db
 | 
			
		||||
from marshm import ma
 | 
			
		||||
from resources import SampleResource, SampleParameterResource
 | 
			
		||||
from healthchecks import health_database_status
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
Main Flask RESTful APIm
 | 
			
		||||
@@ -42,6 +43,7 @@ app.config['FLASK_PIKA_PARAMS'] = {'host': RABBITMQ_HOST,
 | 
			
		||||
                                   'port': 5672,
 | 
			
		||||
                                   'virtual_host': '/'}
 | 
			
		||||
api = Api(app)
 | 
			
		||||
health = HealthCheck(app, "/healthz")
 | 
			
		||||
db.init_app(app)
 | 
			
		||||
ma.init_app(app)
 | 
			
		||||
 | 
			
		||||
@@ -62,6 +64,7 @@ logger.addHandler(handler)
 | 
			
		||||
api.add_resource(SampleResource, "/sample")
 | 
			
		||||
api.add_resource(SampleParameterResource, '/sample/<tag>')
 | 
			
		||||
 | 
			
		||||
health.add_check(health_database_status)
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    app.run(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								src/healthchecks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/healthchecks.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
from db import db
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
Healthchek functions
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__author__ = "@tormakris"
 | 
			
		||||
__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
			
		||||
__module_name__ = "healthchecks"
 | 
			
		||||
__version__text__ = "1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def health_database_status():
 | 
			
		||||
    is_database_working = True
 | 
			
		||||
    output = 'database is ok'
 | 
			
		||||
    try:
 | 
			
		||||
        db.session.execute('SELECT 1')
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        output = str(e)
 | 
			
		||||
        is_database_working = False
 | 
			
		||||
    return is_database_working, output
 | 
			
		||||
		Reference in New Issue
	
	Block a user