Skip to content

Commit

Permalink
Registering relation-changed, preventing to be stuck in 'waiting' if …
Browse files Browse the repository at this point in the history
…secrets weren't there at 'start' (#15)
  • Loading branch information
juditnovak authored Oct 31, 2023
1 parent b48f401 commit 5ea3cde
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __init__(self, *args):
self.framework.observe(
getattr(self.database.on, "endpoints_changed"), self._on_endpoints_changed
)
self.framework.observe(
self.on[DATABASE_RELATION].relation_changed, self._on_relation_changed
)
self.framework.observe(
self.on[DATABASE_RELATION].relation_broken, self._on_relation_broken
)
Expand Down Expand Up @@ -329,6 +332,13 @@ def _on_peer_relation_changed(self, _) -> None:

self.unit.status = ActiveStatus()

def _on_relation_changed(self, _) -> None:
"""Handle the database relation broken event."""
if self._database_config:
self.unit.status = ActiveStatus()
else:
self.unit.status = WaitingStatus()

def _on_relation_broken(self, _) -> None:
"""Handle the database relation broken event."""
self._stop_continuous_writes()
Expand Down

0 comments on commit 5ea3cde

Please sign in to comment.