diff --git a/endpoints/misc.py b/endpoints/misc.py index 37a00da..e437138 100644 --- a/endpoints/misc.py +++ b/endpoints/misc.py @@ -1,3 +1,4 @@ +import logging import time from typing import Optional from fastapi import FastAPI @@ -85,6 +86,8 @@ class Misc(FastAPI): """ found_counts: Optional[dict] = await self.redis_cache.get_found_counts() if not isinstance(found_counts, dict): + logging.info("DEBUG: Type of found counts from redis: %s\nContents: %s", + type(found_counts), found_counts) return JSONResponse(status_code=500, content={ 'err': True, 'errorText': 'General failure.', diff --git a/lyric_search/sources/redis_cache.py b/lyric_search/sources/redis_cache.py index f63e4b9..e498b35 100644 --- a/lyric_search/sources/redis_cache.py +++ b/lyric_search/sources/redis_cache.py @@ -93,15 +93,14 @@ class RedisCache: src = src.strip().lower() await self.redis_client.incr(f"returned:{src}") except Exception as e: - file = __file__.rsplit("/", maxsplit=1)[-1] + file: str = __file__.rsplit("/", maxsplit=1)[-1] await self.notifier.send(f"ERROR @ {file}", str(e)) traceback.print_exc() async def get_found_counts(self) -> Optional[dict]: """ Get found counts for all sources (and failed count) - Args: - None + Returns: dict: In the form {'source': count, 'source2': count, ...} """ @@ -110,12 +109,10 @@ class RedisCache: counts: dict[str, int] = {} for src in sources: src_found_count = await self.redis_client.get(f"returned:{src}") - if not isinstance(src_found_count, int): - return None counts[src] = int(src_found_count) # Redis returns bytes return counts except Exception as e: - file = __file__.rsplit("/", maxsplit=1)[-1] + file: str = __file__.rsplit("/", maxsplit=1)[-1] await self.notifier.send(f"ERROR @ {file}", str(e)) traceback.print_exc() return None @@ -184,6 +181,7 @@ class RedisCache: traceback.print_exc() # await self.notifier.send(f"ERROR @ {__file__.rsplit("/", maxsplit=1)[-1]}", f"{str(e)}\nSearch was: {artist} - {song}; fuzzy: {fuzzy_artist} - {fuzzy_song}") return None + async def redis_store(self, sqlite_id: int, lyr_result: LyricsResult) -> None: """ @@ -222,7 +220,7 @@ class RedisCache: await self.notifier.send("INFO", f"Stored {lyr_result.artist} - {lyr_result.song} (related SQLite Row ID: {sqlite_id}) to redis: {newkey}") except Exception as e: - file = __file__.rsplit("/", maxsplit=1)[-1] + file: str = __file__.rsplit("/", maxsplit=1)[-1] await self.notifier.send(f"ERROR @ {file}", f"Failed to store {lyr_result.artist} - {lyr_result.song}\ (SQLite id: {sqlite_id}) to Redis:\n{str(e)}") \ No newline at end of file