Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+b21b1e10.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added InfrahubClient.schema.in_sync method to indicate if a specific branch is in sync across all worker types
16 changes: 12 additions & 4 deletions infrahub_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,7 @@
"""Wait until the schema has converged on the selected branch or the timeout has been reached"""
waited = 0
while True:
status = await self.client.execute_graphql(query=SCHEMA_HASH_SYNC_STATUS, branch_name=branch)
if status["InfrahubStatus"]["summary"]["schema_hash_synced"]:
if await self.in_sync(branch=branch):
self.client.log.info(f"Schema successfully converged after {waited} seconds")
return

Expand All @@ -649,6 +648,11 @@
waited += 1
await asyncio.sleep(delay=1)

async def in_sync(self, branch: Optional[str] = None) -> bool:

Check warning on line 651 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L651

Added line #L651 was not covered by tests
"""Indicate if the schema is in sync across all workers for the provided branch"""
response = await self.client.execute_graphql(query=SCHEMA_HASH_SYNC_STATUS, branch_name=branch)
return response["InfrahubStatus"]["summary"]["schema_hash_synced"]

async def check(self, schemas: list[dict], branch: Optional[str] = None) -> tuple[bool, Optional[dict]]:
branch = branch or self.client.default_branch
url = f"{self.client.address}/api/schema/check?branch={branch}"
Expand Down Expand Up @@ -1041,8 +1045,7 @@
"""Wait until the schema has converged on the selected branch or the timeout has been reached"""
waited = 0
while True:
status = self.client.execute_graphql(query=SCHEMA_HASH_SYNC_STATUS, branch_name=branch)
if status["InfrahubStatus"]["summary"]["schema_hash_synced"]:
if self.in_sync(branch=branch):
self.client.log.info(f"Schema successfully converged after {waited} seconds")
return

Expand All @@ -1053,6 +1056,11 @@
waited += 1
sleep(1)

def in_sync(self, branch: Optional[str] = None) -> bool:

Check warning on line 1059 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L1059

Added line #L1059 was not covered by tests
"""Indicate if the schema is in sync across all workers for the provided branch"""
response = self.client.execute_graphql(query=SCHEMA_HASH_SYNC_STATUS, branch_name=branch)
return response["InfrahubStatus"]["summary"]["schema_hash_synced"]

def check(self, schemas: list[dict], branch: Optional[str] = None) -> tuple[bool, Optional[dict]]:
branch = branch or self.client.default_branch
url = f"{self.client.address}/api/schema/check?branch={branch}"
Expand Down
Loading