Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status page bug fixes #788

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ckanext/nhm/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from beaker.cache import cache_region
from jinja2.filters import do_truncate
from lxml import etree, html
from werkzeug.routing import BuildError

from ckan import model
from ckan.lib import helpers as core_helpers
Expand Down Expand Up @@ -1627,3 +1628,17 @@ def get_status_indicator():
amber_status = [r for r in status_reports if r['state'] == 'ok']
if len(amber_status) > 0:
return 'amber'


def route_exists(route):
"""
Simple helper for checking if a flask route exists.

:param route: endpoint name, as passed to url_for
:return: bool
"""
try:
url = toolkit.url_for(route)
return True
except BuildError:
return False
17 changes: 11 additions & 6 deletions ckanext/nhm/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@

from ckan.plugins import toolkit
import requests
from cachetools import cached, TTLCache


@cached(cache=TTLCache(maxsize=10, ttl=300))
def get_iiif_status():
health = {}
health = {'ping': False}

url = toolkit.config.get('ckanext.iiif.image_server_url')
r = requests.get(url + '/status')
if r.ok:
health['ping'] = True
response_json = r.json()
else:
try:
r = requests.get(url + '/status', timeout=5)
if r.ok:
health['ping'] = True
response_json = r.json()
else:
response_json = {}
except requests.exceptions.RequestException as e:
response_json = {}

health['status'] = response_json.get('status')
Expand Down
2 changes: 2 additions & 0 deletions ckanext/nhm/theme/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{% set status_indicator = h.get_status_indicator() %}
{% macro status_icon() %}
{% if h.route_exists('status.index') %}
<div>
<a href="{{ h.url_for('status.index') }}"
title="{{ _('System status') }}">
Expand All @@ -22,6 +23,7 @@
<i class="fas fa-heartbeat fa-lg"></i>
</a>
</div>
{% endif %}
{% endmacro %}


Expand Down
Loading