Skip to content

Commit

Permalink
add db check to healthcheck (#61)
Browse files Browse the repository at this point in the history
* add db check to healthcheck

* update test
  • Loading branch information
diegocepedaw authored Apr 14, 2020
1 parent 0867f64 commit 5651fe0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/iris_relay/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from urllib3.exceptions import MaxRetryError
import yaml
import falcon
from falcon import (HTTP_200, HTTP_503)
import ujson
import falcon.uri
import os
Expand Down Expand Up @@ -669,9 +670,20 @@ def on_get(self, req, resp):
except IOError:
raise falcon.HTTPNotFound()

resp.status = falcon.HTTP_200
resp.content_type = 'text/plain'
resp.body = health
try:
connection = db.connect()
cursor = connection.cursor()
cursor.execute('SELECT version()')
cursor.close()
connection.close()
except Exception:
resp.status = HTTP_503
resp.content_type = 'text/plain'
resp.body = 'Could not connect to database'
else:
resp.status = HTTP_200
resp.content_type = 'text/plain'
resp.body = health


class GmailVerification(object):
Expand Down
5 changes: 2 additions & 3 deletions test/e2etest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ def test_twilio_message_relay_api():

def test_health():
"""
Should respond to health check
Database is not set up during this should with 503
"""
re = requests.get(host + '/healthcheck')
assert re.status_code == 200
assert re.content == b'GOOD'
assert re.status_code == 503


def test_gmail_verification():
Expand Down

0 comments on commit 5651fe0

Please sign in to comment.