Added amqp to health check
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
e64137ca56
commit
57b757cb41
@ -11,7 +11,7 @@ from db import db
|
||||
from marshm import ma
|
||||
from influxus import influx_db
|
||||
from resources import SampleResource, SampleParameterResource
|
||||
from healthchecks import health_database_status
|
||||
from healthchecks import health_database_status, ampq_connection_status
|
||||
|
||||
import atexit
|
||||
|
||||
@ -70,5 +70,7 @@ api.add_resource(SampleResource, "/sample")
|
||||
api.add_resource(SampleParameterResource, '/sample/<tag>')
|
||||
|
||||
health.add_check(health_database_status)
|
||||
health.add_check(ampq_connection_status)
|
||||
|
||||
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from db import db
|
||||
from magic_ampq import magic_ampq
|
||||
|
||||
"""
|
||||
Healthchek functions
|
||||
@ -21,3 +22,14 @@ def health_database_status():
|
||||
output = str(e)
|
||||
is_database_working = False
|
||||
return is_database_working, output
|
||||
|
||||
|
||||
def ampq_connection_status():
|
||||
if magic_ampq.is_healthy():
|
||||
result = True
|
||||
text = "ampq connection is ok"
|
||||
else:
|
||||
result = False
|
||||
text = "ampq connection is unhealthy"
|
||||
|
||||
return result, text
|
||||
|
@ -90,6 +90,13 @@ class MagicAMPQ:
|
||||
if tries > 10:
|
||||
time.sleep(2)
|
||||
|
||||
def is_healthy(self) -> bool:
|
||||
with self._lock:
|
||||
if not self._pika_channel:
|
||||
return False
|
||||
|
||||
return self._pika_channel.is_open and self._pika_connection.is_open
|
||||
|
||||
|
||||
# instance to be used in the flask app
|
||||
magic_ampq = MagicAMPQ()
|
||||
|
Loading…
Reference in New Issue
Block a user