diff --git a/rbac/management/cache.py b/rbac/management/cache.py index 23344c4f..7085bd47 100644 --- a/rbac/management/cache.py +++ b/rbac/management/cache.py @@ -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.""" diff --git a/rbac/management/seeds.py b/rbac/management/seeds.py index 36906e99..664b1b08 100644 --- a/rbac/management/seeds.py +++ b/rbac/management/seeds.py @@ -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}].") @@ -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