File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,12 @@ class MySQLRouterCharm(ops.CharmBase, abc.ABC):
61
61
_READ_ONLY_X_PORT = 6449
62
62
63
63
refresh : charm_refresh .Common
64
+ # Whether `reconcile` method is allowed to run
65
+ # `False` if `charm_refresh.UnitTearingDown` or `charm_refresh.PeerRelationNotReady` raised
66
+ # Most of the charm code should not run if either of those exceptions is raised
67
+ # However, some charm libs (i.e. data-platform-libs) will break if they do not receive every
68
+ # event they expect (e.g. relation-created)
69
+ _reconcile_allowed : bool
64
70
65
71
def __init__ (self , * args ) -> None :
66
72
super ().__init__ (* args )
@@ -285,6 +291,9 @@ def _update_endpoints(self) -> None:
285
291
286
292
def reconcile (self , event = None ) -> None : # noqa: C901
287
293
"""Handle most events."""
294
+ if not self ._reconcile_allowed :
295
+ logger .debug ("Reconcile not allowed" )
296
+ return
288
297
workload_ = self .get_workload (event = event )
289
298
logger .debug (
290
299
"State of reconcile "
Original file line number Diff line number Diff line change @@ -95,12 +95,14 @@ def __init__(self, *args) -> None:
95
95
# unit(s) tear down
96
96
self .unit .status = ops .MaintenanceStatus ("Tearing down" )
97
97
snap .uninstall ()
98
- exit ()
98
+ self . _reconcile_allowed = False
99
99
except charm_refresh .PeerRelationNotReady :
100
100
self .unit .status = ops .MaintenanceStatus ("Waiting for peer relation" )
101
101
if self .unit .is_leader ():
102
102
self .app .status = ops .MaintenanceStatus ("Waiting for peer relation" )
103
- exit ()
103
+ self ._reconcile_allowed = False
104
+ else :
105
+ self ._reconcile_allowed = True
104
106
105
107
@property
106
108
def _subordinate_relation_endpoint_names (self ) -> typing .Optional [typing .Iterable [str ]]:
You can’t perform that action at this time.
0 commit comments