mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
notify-api-412 use black to enforce python coding style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import Blueprint
|
||||
|
||||
status = Blueprint('status', __name__)
|
||||
status = Blueprint("status", __name__)
|
||||
|
||||
from app.status.views import healthcheck # noqa isort:skip
|
||||
|
||||
@@ -10,9 +10,9 @@ from app.extensions import redis_client
|
||||
from app.status import status
|
||||
|
||||
|
||||
@status.route('/_status', methods=['GET'])
|
||||
@status.route("/_status", methods=["GET"])
|
||||
def show_status():
|
||||
if request.args.get('elb', None) or request.args.get('simple', None):
|
||||
if request.args.get("elb", None) or request.args.get("simple", None):
|
||||
return jsonify(status="ok"), 200
|
||||
else:
|
||||
try:
|
||||
@@ -20,46 +20,66 @@ def show_status():
|
||||
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
|
||||
return (
|
||||
jsonify(
|
||||
status="ok",
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
),
|
||||
200,
|
||||
)
|
||||
|
||||
|
||||
@status.route('/_status/redis', methods=['GET'])
|
||||
@status.route("/_status/redis", methods=["GET"])
|
||||
def show_redis_status():
|
||||
try:
|
||||
try:
|
||||
api_status = {"error": "unexpected error"}
|
||||
redis_uri = current_app.config['REDIS_URL']
|
||||
redis_uri = current_app.config["REDIS_URL"]
|
||||
current_app.logger.info(f"config['REDIS_URL']: {redis_uri}")
|
||||
redis_enabled = current_app.config['REDIS_ENABLED']
|
||||
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}")
|
||||
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}")
|
||||
current_app.logger.exception(
|
||||
f"Redis service failed to respond with {err}"
|
||||
)
|
||||
|
||||
api_status = status_api_client.get_count_of_live_services_and_organizations_cached()
|
||||
api_status = (
|
||||
status_api_client.get_count_of_live_services_and_organizations_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
|
||||
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
|
||||
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