From 6143667af11818d8d45efce20073bfb64899a4f9 Mon Sep 17 00:00:00 2001 From: John Lu <87673068+JohnLu2004@users.noreply.github.com> Date: Sat, 2 Nov 2024 02:14:20 -0400 Subject: [PATCH] Flushed care_static_data prefixed redis keys (#2572) Flushed care_static_data prefixed redis keys (#2572) --------- Co-authored-by: JohnLu2004 Co-authored-by: Aakash Singh --- care/facility/management/commands/load_redis_index.py | 11 +++++++++++ care/facility/tasks/redis_index.py | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/care/facility/management/commands/load_redis_index.py b/care/facility/management/commands/load_redis_index.py index 736f482836..e24175a8bf 100644 --- a/care/facility/management/commands/load_redis_index.py +++ b/care/facility/management/commands/load_redis_index.py @@ -17,6 +17,17 @@ class Command(BaseCommand): help = "Loads static data to redis" def handle(self, *args, **options): + try: + deleted_count = cache.delete_pattern("care_static_data*", itersize=25_000) + self.stdout.write( + f"Deleted {deleted_count} keys with prefix 'care_static_data'" + ) + except Exception as e: + self.stdout.write( + f"Failed to delete keys with prefix 'care_static_data': {e}" + ) + return + if cache.get("redis_index_loading"): self.stdout.write("Redis Index already loading, skipping") return diff --git a/care/facility/tasks/redis_index.py b/care/facility/tasks/redis_index.py index 306fc1352c..901c1be22d 100644 --- a/care/facility/tasks/redis_index.py +++ b/care/facility/tasks/redis_index.py @@ -15,6 +15,13 @@ @shared_task def load_redis_index(): + try: + deleted_count = cache.delete_pattern("care_static_data*", itersize=25_000) + logger.info("Deleted %s keys with prefix 'care_static_data'", deleted_count) + except Exception as e: + logger.error("Failed to delete keys with prefix 'care_static_data': %s", e) + return + if cache.get("redis_index_loading"): logger.info("Redis Index already loading, skipping") return @@ -37,9 +44,9 @@ def load_redis_index(): if load_static_data: load_static_data() except ModuleNotFoundError: - logger.info("Module %s not found", module_path) + logger.debug("Module %s not found", module_path) except Exception as e: - logger.info("Error loading static data for %s: %s", plug.name, e) + logger.error("Error loading static data for %s: %s", plug.name, e) cache.delete("redis_index_loading") logger.info("Redis Index Loaded")