Skip to content

Commit

Permalink
Fix/agent relation (#77)
Browse files Browse the repository at this point in the history
* fix: defer unhandled relation joined

* fix: remove defer
  • Loading branch information
yanksyoon authored Dec 6, 2023
1 parent 8b10218 commit 9666553
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def _on_deprecated_agent_relation_joined(self, event: ops.RelationJoinedEvent) -
"""
container = self.charm.unit.get_container(JENKINS_SERVICE_NAME)
if not container.can_connect() or not self.state.is_storage_ready:
logger.warning("Service not yet ready. Deferring.")
event.defer()
return
# The relation is joined, it cannot be None, hence the type casting.
deprecated_agent_relation_meta = typing.cast(
Expand Down Expand Up @@ -101,6 +103,8 @@ def _on_agent_relation_joined(self, event: ops.RelationJoinedEvent) -> None:
"""
container = self.charm.unit.get_container(JENKINS_SERVICE_NAME)
if not container.can_connect() or not self.state.is_storage_ready:
logger.warning("Service not yet ready. Deferring.")
event.defer()
return
# The relation is joined, it cannot be None, hence the type casting.
agent_relation_meta = typing.cast(
Expand Down Expand Up @@ -144,6 +148,7 @@ def _on_deprecated_agent_relation_departed(self, event: ops.RelationDepartedEven
# the event unit cannot be None.
container = self.charm.unit.get_container(JENKINS_SERVICE_NAME)
if not container.can_connect() or not self.state.is_storage_ready:
logger.warning("Relation departed before service ready.")
return

# The relation data is removed before this particular hook runs, making the name set by the
Expand Down Expand Up @@ -171,6 +176,7 @@ def _on_agent_relation_departed(self, event: ops.RelationDepartedEvent) -> None:
# the event unit cannot be None.
container = self.charm.unit.get_container(JENKINS_SERVICE_NAME)
if not container.can_connect() or not self.state.is_storage_ready:
logger.warning("Relation departed before service ready.")
return

# The relation data is removed before this particular hook runs, making the name set by the
Expand Down

0 comments on commit 9666553

Please sign in to comment.