Skip to content
Snippets Groups Projects
Commit 2caf4cba authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature add-poller-response-caching.

parents c7724cc1 ab1e9d25
No related branches found
No related tags found
No related merge requests found
...@@ -88,10 +88,9 @@ def poller_interface_oids(hostname): ...@@ -88,10 +88,9 @@ def poller_interface_oids(hostname):
@common.require_accepts_json @common.require_accepts_json
def service_category_interfaces(category): def service_category_interfaces(category):
def _interfaces(): def _interfaces(rc, cat):
r = common.get_current_redis() for k in rc.scan_iter(f'interface-services:{cat}:*'):
for k in r.scan_iter(f'interface-services:{category.lower()}:*'): cached_ifc = rc.get(k.decode('utf-8')).decode('utf-8')
cached_ifc = r.get(k.decode('utf-8')).decode('utf-8')
cached_ifc = json.loads(cached_ifc) cached_ifc = json.loads(cached_ifc)
basic_ifc_info = dict() basic_ifc_info = dict()
for k in ['description', 'interface', 'router']: for k in ['description', 'interface', 'router']:
...@@ -104,12 +103,22 @@ def service_category_interfaces(category): ...@@ -104,12 +103,22 @@ def service_category_interfaces(category):
ifc.update(basic_ifc_info) ifc.update(basic_ifc_info)
yield ifc yield ifc
result = list(_interfaces()) category = category.lower()
if not result: r = common.get_current_redis()
return Response( cache_key = f'classifier-cache:poller:service:{category}'
response=f'no info available for service category {category}', result = r.get(cache_key)
status=404,
mimetype="text/html") if result:
result = json.loads(result.decode('utf-8'))
else:
result = list(_interfaces(r, category))
if result:
r.set(cache_key, json.dumps(result).encode('utf-8'))
else:
return Response(
response=f'no info available for service category {category}',
status=404,
mimetype="text/html")
return jsonify(result) return jsonify(result)
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment