Skip to content
Snippets Groups Projects
Commit 1a753e06 authored by Robert Latta's avatar Robert Latta
Browse files

added ignore cache option

parent c6dc7de2
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,11 @@ import json
import logging
import re
from copy import copy
from distutils.util import strtobool
from functools import lru_cache
from typing import Optional, Iterator, List
from flask import Blueprint, Response, current_app
from flask import Blueprint, Response, current_app, request
from redis import Redis
from inventory_provider.db.ims import IMS_SERVICE_NAMES
......@@ -296,8 +297,15 @@ def get_juniper_link_info(source_equipment: str, interface: str) -> Response:
cache_key = \
f'ims-classifier-cache:juniper:{ims_source_equipment}:{ims_interface}'
# result = r.get(cache_key)
result = False
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
ignore_cache = strtobool(ignore_cache)
except ValueError:
ignore_cache = False
if ignore_cache:
result = False
else:
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
......@@ -420,8 +428,15 @@ def peer_info(address_str: str) -> Response:
cache_key = f'ims-classifier-cache:peer:{address_str}'
# result = r.get(cache_key)
result = False
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
ignore_cache = strtobool(ignore_cache)
except ValueError:
ignore_cache = False
if ignore_cache:
result = False
else:
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
......@@ -494,8 +509,15 @@ def get_trap_metadata(source_equipment: str, interface: str, circuit_id: str) \
r = common.get_current_redis()
result = r.get(cache_key)
result = False
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
ignore_cache = strtobool(ignore_cache)
except ValueError:
ignore_cache = False
if ignore_cache:
result = False
else:
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
......@@ -573,8 +595,15 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \
cache_key = \
f'ims-classifier-cache:fiberlink:{ne_name_str}:{object_name_str}'
# result = r.get(cache_key)
result = False
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
ignore_cache = strtobool(ignore_cache)
except ValueError:
ignore_cache = False
if ignore_cache:
result = False
else:
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
......@@ -656,8 +685,15 @@ def get_coriant_info(equipment_name: str, entity_string: str) -> Response:
cache_key = 'ims-classifier-cache:coriant:%s:%s' % (
equipment_name, entity_string)
# result = r.get(cache_key)
result = False
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
ignore_cache = strtobool(ignore_cache)
except ValueError:
ignore_cache = False
if ignore_cache:
result = False
else:
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
......
......@@ -25,7 +25,12 @@ logger = logging.getLogger(__name__)
@app.task(base=InventoryTask, bind=True, name='update_fibre_spans_ims')
@log_task_entry_and_exit
def update_fibre_spans(self, use_current=False):
r = get_next_redis(InventoryTask.config)
if use_current:
r = get_current_redis(InventoryTask.config)
# scan with bigger batches, to mitigate network latency effects
else:
r = get_next_redis(InventoryTask.config)
rp = r.pipeline()
# scan with bigger batches, to mitigate network latency effects
for key in r.scan_iter('ims:ne_fibre_spans:*', count=1000):
......@@ -50,7 +55,6 @@ def update_interfaces_to_port_ids_ims(self, use_current=False):
if use_current:
r = get_current_redis(InventoryTask.config)
# scan with bigger batches, to mitigate network latency effects
else:
r = get_next_redis(InventoryTask.config)
......
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