From 1d7bf54bfc40442086af5e33b38793df59ac3903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 30 Dec 2021 12:30:09 +0100 Subject: [PATCH] chg: Improve logging when something is broken when caching --- bgpranking/bgpranking.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bgpranking/bgpranking.py b/bgpranking/bgpranking.py index a5588d7..9c53cbd 100644 --- a/bgpranking/bgpranking.py +++ b/bgpranking/bgpranking.py @@ -60,10 +60,14 @@ class BGPRanking(): def _ranking_cache_wrapper(self, key): if not self.cache.exists(key): if self.ranking.exists(key): - content: List[Tuple[bytes, float]] = self.ranking.zrangebyscore(key, '-Inf', '+Inf', withscores=True) - # Cache for 10 hours - self.cache.zadd(key, {value: rank for value, rank in content}) - self.cache.expire(key, 36000) + try: + content: List[Tuple[bytes, float]] = self.ranking.zrangebyscore(key, '-Inf', '+Inf', withscores=True) + # Cache for 10 hours + self.cache.zadd(key, {value: rank for value, rank in content}) + self.cache.expire(key, 36000) + except Exception as e: + self.logger.exception(f'Something went poorly when caching {key}.') + raise e def asns_global_ranking(self, date: Optional[Dates]=None, source: Union[list, str]='', ipversion: str='v4', limit: int=100):