fix: Better handling of cache issues

pull/67/head
Raphaël Vinot 2020-02-11 17:03:25 +01:00
parent fcdbad4a3c
commit e7b97d23b7
1 changed files with 7 additions and 3 deletions

View File

@ -85,12 +85,16 @@ class Lookyloo():
self.redis.hmset(str(report_dir), cache)
self.redis.hset('lookup_dirs', uuid, str(report_dir))
def report_cache(self, report_dir: Union[str, Path]) -> Dict:
def report_cache(self, report_dir: Union[str, Path]) -> Optional[Dict[str, Union[str, int]]]:
if isinstance(report_dir, Path):
report_dir = str(report_dir)
cached = self.redis.hgetall(report_dir)
cached['redirects'] = json.loads(cached['redirects'])
return cached
if all(key in ['uuid', 'title', 'timestamp', 'url', 'redirects'] for key in cached):
cached['redirects'] = json.loads(cached['redirects'])
return cached
self.logger.warning(f'Cache ({report_dir}) is invalid: {json.dumps(report_dir, indent=2)}')
return None
def _init_existing_dumps(self) -> None:
for report_dir in self.report_dirs: