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")