From c5717bfb22f209a3d3d21d7c7bf800c174537d9b Mon Sep 17 00:00:00 2001 From: Nikita Melkozerov Date: Wed, 23 Oct 2024 11:03:42 +0200 Subject: [PATCH] Do not ping azure subscriptions which are good to go (#639) --- .../cloud_accounts/azure_subscription_repo.py | 13 +++++++++---- .../cloud_accounts/azure_subscription_service.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fixbackend/cloud_accounts/azure_subscription_repo.py b/fixbackend/cloud_accounts/azure_subscription_repo.py index 6548f6ae..9a2f4c8e 100644 --- a/fixbackend/cloud_accounts/azure_subscription_repo.py +++ b/fixbackend/cloud_accounts/azure_subscription_repo.py @@ -120,11 +120,16 @@ async def get_by_tenant(self, tenant_id: WorkspaceId) -> Optional[AzureSubscript return entity.to_model() - async def list_created_after(self, time: datetime) -> List[AzureSubscriptionCredentials]: + async def list_created_after( + self, time: datetime, can_access_azure_account: Optional[bool] = None + ) -> List[AzureSubscriptionCredentials]: async with self._session_maker() as session: - query = select(AzureSubscriptionCredentialsEntity).filter( - AzureSubscriptionCredentialsEntity.created_at > time - ) + filters = [AzureSubscriptionCredentialsEntity.created_at > time] + if can_access_azure_account is not None: + filters.append( + AzureSubscriptionCredentialsEntity.can_access_azure_account.is_(can_access_azure_account) + ) + query = select(AzureSubscriptionCredentialsEntity).filter(*filters) result = await session.execute(query) return [entity.to_model() for entity in result.scalars()] diff --git a/fixbackend/cloud_accounts/azure_subscription_service.py b/fixbackend/cloud_accounts/azure_subscription_service.py index c3eb22aa..da91f7fb 100644 --- a/fixbackend/cloud_accounts/azure_subscription_service.py +++ b/fixbackend/cloud_accounts/azure_subscription_service.py @@ -139,7 +139,7 @@ async def _import_subscriptions(self, creds: AzureSubscriptionCredentials) -> No async def _ping_new_subscriptions(self) -> None: created_less_than_30_minutes_ago = await self.azure_subscriptions_repo.list_created_after( - utc() - timedelta(minutes=30) + utc() - timedelta(minutes=30), can_access_azure_account=False ) async with asyncio.TaskGroup() as tg: