Skip to content

Commit

Permalink
Flushed care_static_data prefixed redis keys (#2572)
Browse files Browse the repository at this point in the history
Flushed care_static_data prefixed redis keys (#2572)

---------

Co-authored-by: JohnLu2004 <JohnLu10212004@gmail.com>
Co-authored-by: Aakash Singh <mail@singhaakash.dev>
  • Loading branch information
3 people authored Nov 2, 2024
1 parent 67c63d9 commit 6143667
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions care/facility/management/commands/load_redis_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions care/facility/tasks/redis_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

0 comments on commit 6143667

Please sign in to comment.