Skip to content

Commit

Permalink
fix: cache iiif status response for 300s
Browse files Browse the repository at this point in the history
and make request timeout after 5s
  • Loading branch information
alycejenni committed Jul 12, 2024
1 parent 3c3b247 commit b3cfdd9
Showing 1 changed file with 11 additions and 6 deletions.
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=1024, 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

0 comments on commit b3cfdd9

Please sign in to comment.