mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
finally fix redis
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from flask import current_app, jsonify, request
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from redis import RedisError
|
||||
|
||||
from app import status_api_client, version
|
||||
from app.extensions import redis_client
|
||||
from app.status import status
|
||||
|
||||
|
||||
@@ -12,11 +17,49 @@ def show_status():
|
||||
else:
|
||||
try:
|
||||
api_status = status_api_client.get_status()
|
||||
except HTTPError as e:
|
||||
except HTTPError as err:
|
||||
current_app.logger.exception("API failed to respond")
|
||||
return jsonify(status="error", message=str(e.message)), 500
|
||||
return jsonify(status="error", message=str(err.message)), 500
|
||||
return jsonify(
|
||||
status="ok",
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__), 200
|
||||
|
||||
|
||||
@status.route('/_status/redis', methods=['GET'])
|
||||
def show_redis_status():
|
||||
try:
|
||||
try:
|
||||
api_status = {"error": "unexpected error"}
|
||||
redis_uri = current_app.config['REDIS_URL']
|
||||
current_app.logger.info(f"config['REDIS_URL']: {redis_uri}")
|
||||
redis_enabled = current_app.config['REDIS_ENABLED']
|
||||
current_app.logger.info(f"config['REDIS_ENABLED']: {redis_enabled}")
|
||||
if redis_enabled:
|
||||
current_app.logger.info("config['REDIS_ENABLED'] evaluates as True")
|
||||
|
||||
try:
|
||||
now = time.time()
|
||||
redis_client.set('mytestkey', now)
|
||||
val = redis_client.get('mytestkey')
|
||||
current_app.logger.info(f"Retrieved value from redis for mytestkey is: {val}")
|
||||
except RedisError as err:
|
||||
current_app.logger.exception(f"Redis service failed to respond with {err}")
|
||||
|
||||
api_status = status_api_client.get_count_of_live_services_and_organisations_cached()
|
||||
except HTTPError as err:
|
||||
current_app.logger.exception("API failed to respond")
|
||||
return jsonify(status="error", message=str(err.message)), 500
|
||||
return jsonify(
|
||||
status="ok",
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__), 200
|
||||
except Exception as err:
|
||||
current_app.logger.exception(F"Unhandled exception: {err} - {traceback.format_exc()}")
|
||||
return jsonify(
|
||||
status=f"error: {err}",
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__), 500
|
||||
|
||||
Reference in New Issue
Block a user