Skip to content

Commit

Permalink
Do not ping azure subscriptions which are good to go (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Oct 23, 2024
1 parent aa95940 commit c5717bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions fixbackend/cloud_accounts/azure_subscription_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]

Expand Down
2 changes: 1 addition & 1 deletion fixbackend/cloud_accounts/azure_subscription_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c5717bf

Please sign in to comment.