mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-23 11:51:05 -05:00
finally fix redis
This commit is contained in:
BIN
app/assets/images/email-template/us-flag.png
Normal file
BIN
app/assets/images/email-template/us-flag.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -7,7 +7,7 @@ if os.environ.get('VCAP_APPLICATION'):
|
||||
# from app.cloudfoundry_config import extract_cloudfoundry_config
|
||||
# extract_cloudfoundry_config()
|
||||
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
|
||||
os.environ['REDIS_URL'] = vcap_services['aws-elasticache-redis'][0]['credentials']['uri']
|
||||
os.environ['REDIS_URL'] = vcap_services['aws-elasticache-redis'][0]['credentials']['uri'].replace("redis", "rediss")
|
||||
|
||||
|
||||
class Config(object):
|
||||
@@ -128,9 +128,6 @@ class Development(Config):
|
||||
ASSET_PATH = '/static/'
|
||||
LOGO_CDN_DOMAIN = 'static-logos.notify.tools' # replace with our own CDN
|
||||
|
||||
REDIS_URL = os.environ.get('DEV_REDIS_URL', 'http://redis:6379')
|
||||
REDIS_ENABLED = True
|
||||
|
||||
|
||||
class Test(Development):
|
||||
NOTIFY_ADMIN_API_CACHE_ENABLED = True
|
||||
@@ -221,9 +218,6 @@ class Live(Config):
|
||||
ASSET_PATH = '/static/' # TODO use a CDN
|
||||
LOGO_CDN_DOMAIN = 'static-logos.notifications.service.gov.uk' # TODO use our own CDN
|
||||
|
||||
REDIS_URL = os.environ.get('REDIS_URL')
|
||||
REDIS_ENABLED = True
|
||||
|
||||
ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET')
|
||||
ADMIN_CLIENT_USER_NAME = os.environ.get('ADMIN_CLIENT_USERNAME')
|
||||
API_HOST_NAME = os.environ.get('API_HOST_NAME')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
from app.notify_client import NotifyAdminAPIClient, cache
|
||||
|
||||
|
||||
class StatusApiClient(NotifyAdminAPIClient):
|
||||
@@ -10,5 +10,9 @@ class StatusApiClient(NotifyAdminAPIClient):
|
||||
def get_count_of_live_services_and_organisations(self):
|
||||
return self.get(url='/_status/live-service-and-organisation-counts')
|
||||
|
||||
@cache.set('live-service-and-organisation-counts', ttl_in_seconds=3600)
|
||||
def get_count_of_live_services_and_organisations_cached(self):
|
||||
return self.get(url='/_status/live-service-and-organisation-counts')
|
||||
|
||||
|
||||
status_api_client = StatusApiClient()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,10 +14,13 @@
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.linting.flake8Enabled": true,
|
||||
"python.pythonPath": "/usr/local/bin/python",
|
||||
"python.defaultInterpreterPath": "/usr/bin/python3",
|
||||
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
|
||||
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
|
||||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8"
|
||||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
|
||||
"python.analysis.extraPaths": [
|
||||
"/home/vscode/.local/lib/python3.9/site-packages"
|
||||
]
|
||||
},
|
||||
"extensions": [
|
||||
"donjayamanne.python-extension-pack",
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_load_cloudfoundry_config_if_available(reload_config):
|
||||
os.environ['VCAP_SERVICES'] = json.dumps({
|
||||
'aws-elasticache-redis': [{
|
||||
'credentials': {
|
||||
'uri': 'redis uri'
|
||||
'uri': 'redis://xxx:6379'
|
||||
}
|
||||
}],
|
||||
})
|
||||
@@ -44,8 +44,8 @@ def test_load_cloudfoundry_config_if_available(reload_config):
|
||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||
importlib.reload(config)
|
||||
|
||||
assert os.environ['REDIS_URL'] == 'redis uri'
|
||||
assert config.Config.REDIS_URL == 'redis uri'
|
||||
assert os.environ['REDIS_URL'] == 'rediss://xxx:6379'
|
||||
assert config.Config.REDIS_URL == 'rediss://xxx:6379'
|
||||
|
||||
|
||||
def test_load_config_if_cloudfoundry_not_available(reload_config):
|
||||
|
||||
@@ -426,7 +426,7 @@ def test_all_endpoints_are_covered(navigation_instance):
|
||||
covered_endpoints = (
|
||||
navigation_instance.endpoints_with_navigation +
|
||||
EXCLUDED_ENDPOINTS +
|
||||
('static', 'status.show_status', 'metrics')
|
||||
('static', 'status.show_status', 'status.show_redis_status', 'metrics')
|
||||
)
|
||||
|
||||
for endpoint in all_endpoints:
|
||||
|
||||
Reference in New Issue
Block a user