From 801edc7cc97d038c9b8283fa6add349a5bc2524c Mon Sep 17 00:00:00 2001 From: halo Date: Tue, 26 Nov 2024 09:50:17 +0800 Subject: [PATCH] perf: After optimizing the execution of the azure vault task, the data is out of sync --- apps/accounts/backends/__init__.py | 3 --- apps/accounts/backends/azure/service.py | 1 - apps/accounts/tasks/vault.py | 3 ++- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/accounts/backends/__init__.py b/apps/accounts/backends/__init__.py index 5b880da68..f696b67c8 100644 --- a/apps/accounts/backends/__init__.py +++ b/apps/accounts/backends/__init__.py @@ -13,9 +13,6 @@ logger = get_logger(__file__) def get_vault_client(raise_exception=False, **kwargs): tp = kwargs.get('VAULT_BACKEND') if kwargs.get('VAULT_ENABLED') else VaultTypeChoices.local - # TODO: Temporary processing, subsequent deletion - tp = VaultTypeChoices.local if tp == VaultTypeChoices.azure else tp - try: module_path = f'apps.accounts.backends.{tp}.main' client = import_module(module_path).Vault(**kwargs) diff --git a/apps/accounts/backends/azure/service.py b/apps/accounts/backends/azure/service.py index c91fd145a..800687ee6 100644 --- a/apps/accounts/backends/azure/service.py +++ b/apps/accounts/backends/azure/service.py @@ -36,7 +36,6 @@ class AZUREVaultClient(object): secret = self.client.get_secret(name, version) return secret.value except (ResourceNotFoundError, ClientAuthenticationError) as e: - logger.error(f'get: {name} {str(e)}') return '' def create(self, name, secret): diff --git a/apps/accounts/tasks/vault.py b/apps/accounts/tasks/vault.py index 3a641b2b9..a3de20c5f 100644 --- a/apps/accounts/tasks/vault.py +++ b/apps/accounts/tasks/vault.py @@ -52,7 +52,8 @@ def sync_secret_to_vault(): for model in to_sync_models: instances += list(model.objects.all()) - with ThreadPoolExecutor(max_workers=10) as executor: + max_workers = 1 if VaultTypeChoices.azure == vault_client.type else max_workers = 10 + with ThreadPoolExecutor(max_workers=max_workers) as executor: tasks = [executor.submit(sync_instance, instance) for instance in instances] for future in as_completed(tasks):