Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Oct 11, 2024
1 parent 57904ef commit 4e5ddd1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/cosl/coordinated_workers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def publish_data(
for relation in self._relations:
if relation:
if not self._has_worker_published(relation):
log.debug("Worker %s hasn't yet published its data", relation.id)
log.debug("Worker %s hasn't yet published its data", relation.app.name)
continue
local_app_databag = ClusterProviderAppData(
worker_config=worker_config,
Expand Down Expand Up @@ -407,24 +407,26 @@ def get_address_from_role(self, role: str) -> Optional[str]:
return None

def _has_worker_published(self, relation: ops.Relation) -> bool:
"""Verify that the worker has published its data.
"""Verify that each worker unit and the worker leader have published their data to the cluster relation.
- unit address is published
- roles are published
"""
if not relation.app:
return False
if len(relation.units) == 0:
if not relation.app or not relation.units or not relation.data:
return False

# check if unit data is published
for worker_unit in relation.units:
try:
ClusterRequirerUnitData.load(relation.data[worker_unit])
if self._charm.unit.is_leader():
ClusterRequirerAppData.load(relation.data[relation.app])
except DataValidationError as e:
log.info(
f"invalid databag contents while checking if worker has published data: {e}"
)
except DataValidationError:
return False

# check if app data is published
if self._charm.unit.is_leader():
try:
ClusterRequirerAppData.load(relation.data[relation.app])
except DataValidationError:
return False

return True
Expand Down

0 comments on commit 4e5ddd1

Please sign in to comment.