minor
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | import logging | ||||||
| import time | import time | ||||||
| from typing import Optional | from typing import Optional | ||||||
| from fastapi import FastAPI | from fastapi import FastAPI | ||||||
| @@ -85,6 +86,8 @@ class Misc(FastAPI): | |||||||
|         """ |         """ | ||||||
|         found_counts: Optional[dict] = await self.redis_cache.get_found_counts() |         found_counts: Optional[dict] = await self.redis_cache.get_found_counts() | ||||||
|         if not isinstance(found_counts, dict): |         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={ |             return JSONResponse(status_code=500, content={ | ||||||
|                 'err': True, |                 'err': True, | ||||||
|                 'errorText': 'General failure.', |                 'errorText': 'General failure.', | ||||||
|   | |||||||
| @@ -93,15 +93,14 @@ class RedisCache: | |||||||
|             src = src.strip().lower() |             src = src.strip().lower() | ||||||
|             await self.redis_client.incr(f"returned:{src}") |             await self.redis_client.incr(f"returned:{src}") | ||||||
|         except Exception as e: |         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))             |             await self.notifier.send(f"ERROR @ {file}", str(e))             | ||||||
|             traceback.print_exc() |             traceback.print_exc() | ||||||
|          |          | ||||||
|     async def get_found_counts(self) -> Optional[dict]: |     async def get_found_counts(self) -> Optional[dict]: | ||||||
|         """ |         """ | ||||||
|         Get found counts for all sources (and failed count) |         Get found counts for all sources (and failed count) | ||||||
|         Args: |          | ||||||
|             None |  | ||||||
|         Returns: |         Returns: | ||||||
|             dict: In the form {'source': count, 'source2': count, ...} |             dict: In the form {'source': count, 'source2': count, ...} | ||||||
|         """ |         """ | ||||||
| @@ -110,12 +109,10 @@ class RedisCache: | |||||||
|             counts: dict[str, int] = {} |             counts: dict[str, int] = {} | ||||||
|             for src in sources: |             for src in sources: | ||||||
|                 src_found_count = await self.redis_client.get(f"returned:{src}") |                 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 |                 counts[src] = int(src_found_count) # Redis returns bytes | ||||||
|             return counts |             return counts | ||||||
|         except Exception as e: |         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))              |             await self.notifier.send(f"ERROR @ {file}", str(e))              | ||||||
|             traceback.print_exc() |             traceback.print_exc() | ||||||
|             return None |             return None | ||||||
| @@ -184,6 +181,7 @@ class RedisCache: | |||||||
|             traceback.print_exc() |             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}")             |             # 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 |             return None | ||||||
|  |          | ||||||
|     async def redis_store(self, sqlite_id: int, |     async def redis_store(self, sqlite_id: int, | ||||||
|                           lyr_result: LyricsResult) -> None: |                           lyr_result: LyricsResult) -> None: | ||||||
|         """ |         """ | ||||||
| @@ -222,7 +220,7 @@ class RedisCache: | |||||||
|             await self.notifier.send("INFO", |             await self.notifier.send("INFO", | ||||||
|                                     f"Stored {lyr_result.artist} - {lyr_result.song} (related SQLite Row ID: {sqlite_id}) to redis: {newkey}") |                                     f"Stored {lyr_result.artist} - {lyr_result.song} (related SQLite Row ID: {sqlite_id}) to redis: {newkey}") | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             file = __file__.rsplit("/", maxsplit=1)[-1] |             file: str = __file__.rsplit("/", maxsplit=1)[-1] | ||||||
|             await self.notifier.send(f"ERROR @ {file}", |             await self.notifier.send(f"ERROR @ {file}", | ||||||
|                                      f"Failed to store {lyr_result.artist} - {lyr_result.song}\ |                                      f"Failed to store {lyr_result.artist} - {lyr_result.song}\ | ||||||
|                                          (SQLite id: {sqlite_id}) to Redis:\n{str(e)}") |                                          (SQLite id: {sqlite_id}) to Redis:\n{str(e)}") | ||||||
		Reference in New Issue
	
	Block a user