Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1130 from petracihalova/seeds_debug…
Browse files Browse the repository at this point in the history
…_logs

add temporary logs for debugging the purge_cache() issue
  • Loading branch information
petracihalova authored Jun 26, 2024
2 parents 409d26f + 68babaa commit a006dd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
12 changes: 11 additions & 1 deletion rbac/management/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,18 @@ def delete_all_policies_for_tenant(self):
with self.delete_handler(err_msg):
logger.info("Deleting entire policy cache for tenant %s", self.tenant)
keys = self.connection.keys(self.key_for("*"))
logger.info(f"Content of 'keys' variable: {keys}")
if keys:
self.connection.delete(*keys)
try:
self.connection.delete(*keys)
except Exception as e:
logger.error(
f"An exception occurred inside delete_all_policies_for_tenant() for tenant {self.tenant} "
f"withing line 'if keys': {e}"
)
raise e
logger.info(f"End of 'with self.delete_handler' for tenant {self.tenant}")
logger.info(f"End of 'delete_all_policies_for_tenant' for tenant {self.tenant}")

def save_policy(self, uuid, sub_key, policy):
"""Write the policy for a given user for a given sub_key (application_offset_limit) to Redis."""
Expand Down
26 changes: 22 additions & 4 deletions rbac/management/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@
def on_complete(progress, tenant):
"""Explicitly close the connection for the thread."""
logger.info(f"Purging policy cache for tenant {tenant.org_id} [{progress}].")
cache = AccessCache(tenant.org_id)
cache.delete_all_policies_for_tenant()
connections.close_all()
try:
cache = AccessCache(tenant.org_id)
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 1: {e}")
raise e

try:
cache.delete_all_policies_for_tenant()
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 2: {e}")
raise e

try:
connections.close_all()
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 3: {e}")
raise e
logger.info(f"Finished purging policy cache for tenant {tenant.org_id} [{progress}].")


Expand Down Expand Up @@ -74,4 +88,8 @@ def purge_cache():
tenant_count = tenants.count()
for idx, tenant in enumerate(list(tenants)):
progress = f"[{idx + 1} of {tenant_count}]."
executor.submit(on_complete, progress, tenant)
try:
executor.submit(on_complete, progress, tenant)
except Exception as e:
logger.error(f"An exception occurred inside purge_cache() for {tenant}: {e}")
raise e

0 comments on commit a006dd5

Please sign in to comment.