From 87614d870897ebbf0971f2b4ba0844e73414d2b4 Mon Sep 17 00:00:00 2001 From: Mia Altieri Date: Tue, 28 Nov 2023 15:49:25 +0000 Subject: [PATCH] fix scale down --- src/charm.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index 885d8c076..a3a54f966 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1315,9 +1315,9 @@ def check_relation_broken_or_scale_down(self, event: RelationDepartedEvent) -> N Relation departed and relation broken events occur during scaling down or during relation removal, only relation departed events have access to metadata to determine which case. """ - self.set_scaling_down(event) + scaling_down = self.set_scaling_down(event) - if self.is_scaling_down(event.relation.id): + if scaling_down: logger.info( "Scaling down the application, no need to process removed relation in broken hook." ) @@ -1332,12 +1332,14 @@ def has_departed_run(self, rel_id: int) -> bool: rel_departed_key = self._generate_relation_departed_key(rel_id) return rel_departed_key in self.unit_peer_data - def set_scaling_down(self, event: RelationDepartedEvent) -> None: + def set_scaling_down(self, event: RelationDepartedEvent) -> bool: """Sets whether or not the current unit is scaling down.""" # check if relation departed is due to current unit being removed. (i.e. scaling down the # application.) rel_departed_key = self._generate_relation_departed_key(event.relation.id) - self.unit_peer_data[rel_departed_key] = json.dumps(event.departing_unit == self.unit) + scaling_down = json.dumps(event.departing_unit == self.unit) + self.unit_peer_data[rel_departed_key] = scaling_down + return scaling_down @staticmethod def _generate_relation_departed_key(rel_id: int) -> str: