From 76ccb99666092e866be37009dd18df49e83cd1fb Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Thu, 3 Mar 2016 16:41:21 +0000 Subject: [PATCH] Fixed up the health check page --- app.py | 11 +---------- app/__init__.py | 12 ------------ app/status/views/healthcheck.py | 28 ++++++++++++++-------------- app/version.py | 5 +++-- scripts/update_version_file.sh | 7 +++++++ 5 files changed, 25 insertions(+), 38 deletions(-) create mode 100755 scripts/update_version_file.sh diff --git a/app.py b/app.py index a3da372f0..445f95cd5 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,6 @@ import os from flask.ext.script import Manager, Server -from flask_migrate import Migrate, MigrateCommand -from app import (create_app, get_app_version) +from app import create_app application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'development') @@ -17,13 +16,5 @@ def list_routes(): print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule)) -@manager.command -def app_version(): - """ - Retrieve the version of the api. - """ - return get_app_version() - - if __name__ == '__main__': manager.run() diff --git a/app/__init__.py b/app/__init__.py index 3f8e61989..94a1c1d86 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -183,15 +183,3 @@ def register_errorhandlers(application): return useful_headers_after_request(resp) for errcode in [401, 404, 403, 500]: application.errorhandler(errcode)(render_error) - - -def get_app_version(): - build = 'n/a' - build_time = "n/a" - try: - from app import version - build = version.__build__ - build_time = version.__time__ - except: - pass - return build, build_time diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index 24337761b..e5c4051a6 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -1,18 +1,18 @@ from flask import jsonify +from flask import request + +from app import version + from app.status import status - -@status.route('/_status') -def status(): - from app import (get_app_version, status_api_client) - api_status = 'n/a' - try: - api_status = status_api_client.get_status() - except: - api_status = 'n/a' - build, build_time = get_app_version() - return jsonify(status="ok", - api_status=api_status, - api_build=build, - api_built_time=build_time), 200 +@status.route('/_status', methods=['GET']) +def show_status(): + if request.args.get('elb', None): + return jsonify(status="ok"), 200 + else: + return jsonify( + status="ok", + travis_commit=version.__travis_commit__, + travis_build_number=version.__travis_job_number__, + build_time=version.__time__), 200 diff --git a/app/version.py b/app/version.py index 62a3e5dfd..1defd614d 100644 --- a/app/version.py +++ b/app/version.py @@ -1,2 +1,3 @@ -__build__ = "" -__time__ = "" +__travis_commit__ = "dev" +__time__ = "dev" +__travis_job_number__ = "dev" diff --git a/scripts/update_version_file.sh b/scripts/update_version_file.sh new file mode 100755 index 000000000..231c210b7 --- /dev/null +++ b/scripts/update_version_file.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +# Update the version file of the project from the Travis build details +# +sed -i -e "s/__travis_commit__ =.*/__travis_commit__ = \"$TRAVIS_COMMIT\"/g" ./app/version.py +sed -i -e "s/__travis_job_number__ =.*/__travis_job_number__ = \"$TRAVIS_BUILD_NUMBER\"/g" ./app/version.py +sed -i -e "s/__time__ =.*/__time__ = \"$(date +%Y-%m-%d:%H:%M:%S)\"/g" ./app/version.py \ No newline at end of file