2016-04-29 12:59:36 +01:00
|
|
|
from flask import (
|
|
|
|
|
jsonify,
|
|
|
|
|
Blueprint,
|
2017-10-17 15:51:42 +01:00
|
|
|
request
|
2016-04-29 12:59:36 +01:00
|
|
|
)
|
2016-03-03 15:18:12 +00:00
|
|
|
|
|
|
|
|
from app import db, version
|
2019-04-11 13:38:21 +01:00
|
|
|
from app.dao.services_dao import dao_count_live_services
|
2020-02-17 11:12:54 +00:00
|
|
|
from app.dao.organisation_dao import dao_count_organisations_with_live_services
|
2016-03-03 15:18:12 +00:00
|
|
|
|
2016-01-14 16:13:27 +00:00
|
|
|
status = Blueprint('status', __name__)
|
2015-12-15 17:14:13 +00:00
|
|
|
|
|
|
|
|
|
2018-10-26 18:02:41 +01:00
|
|
|
@status.route('/', methods=['GET'])
|
2016-01-14 17:45:30 +00:00
|
|
|
@status.route('/_status', methods=['GET', 'POST'])
|
2016-01-14 16:13:27 +00:00
|
|
|
def show_status():
|
2018-03-28 17:19:02 +01:00
|
|
|
if request.args.get('simple', None):
|
2016-03-03 15:18:12 +00:00
|
|
|
return jsonify(status="ok"), 200
|
|
|
|
|
else:
|
|
|
|
|
return jsonify(
|
2017-08-31 12:14:04 +01:00
|
|
|
status="ok", # This should be considered part of the public API
|
2016-03-03 16:27:13 +00:00
|
|
|
travis_commit=version.__travis_commit__,
|
|
|
|
|
travis_build_number=version.__travis_job_number__,
|
|
|
|
|
build_time=version.__time__,
|
2016-03-03 15:18:12 +00:00
|
|
|
db_version=get_db_version()), 200
|
|
|
|
|
|
|
|
|
|
|
2019-04-11 13:38:21 +01:00
|
|
|
@status.route('/_status/live-service-and-organisation-counts')
|
|
|
|
|
def live_service_and_organisation_counts():
|
|
|
|
|
return jsonify(
|
2020-02-17 11:12:54 +00:00
|
|
|
organisations=dao_count_organisations_with_live_services(),
|
2019-04-11 13:38:21 +01:00
|
|
|
services=dao_count_live_services(),
|
|
|
|
|
), 200
|
|
|
|
|
|
|
|
|
|
|
2016-03-03 15:18:12 +00:00
|
|
|
def get_db_version():
|
2017-10-17 15:51:42 +01:00
|
|
|
query = 'SELECT version_num FROM alembic_version'
|
|
|
|
|
full_name = db.session.execute(query).fetchone()[0]
|
|
|
|
|
return full_name
|