Skip to content

Commit

Permalink
fix: refactor logic in _update_workload
Browse files Browse the repository at this point in the history
Refactor the order of actions to better prevent things changing between the guards
and the config creation
  • Loading branch information
nsklikas committed Apr 22, 2024
1 parent 817c10d commit 5e00e2f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ def _update_workload(self, event: HookEvent) -> None:
return

self._create_token()

if not self._container.isdir(LOG_FOLDER):
self._container.make_dir(path=LOG_FOLDER, make_parents=True)
logger.info(f"Created directory {LOG_FOLDER}")

if not self.model.relations[DATABASE_RELATION_NAME]:
self.unit.status = BlockedStatus("Missing required relation with postgresql")
return
Expand All @@ -354,13 +359,6 @@ def _update_workload(self, event: HookEvent) -> None:
self.unit.status = BlockedStatus("Please run schema-upgrade action")
return

# if openfga relation exists, make sure the address is updated
self.openfga_relation.update_server_info(http_api_url=self.http_ingress.url)

if not self._container.isdir(LOG_FOLDER):
self._container.make_dir(path=LOG_FOLDER, make_parents=True)
logger.info(f"Created directory {LOG_FOLDER}")

self._container.add_layer("openfga", self._pebble_layer, combine=True)
if not self._ready():
logger.info("workload container not ready - deferring")
Expand All @@ -375,6 +373,9 @@ def _update_workload(self, event: HookEvent) -> None:
"Failed to restart the container, please consult the logs"
)
return

# if openfga relation exists, make sure the address is updated
self.openfga_relation.update_server_info(http_api_url=self.http_ingress.url)
self.unit.status = ActiveStatus()

def _on_peer_relation_changed(self, event: RelationChangedEvent) -> None:
Expand Down Expand Up @@ -464,7 +465,7 @@ def _ready(self) -> bool:
env_vars = service.environment
for setting in REQUIRED_SETTINGS:
if not env_vars.get(setting, ""):
self.unit.status = BlockedStatus(
self.unit.status = WaitingStatus(
"{} configuration value not set".format(setting),
)
return False
Expand Down

0 comments on commit 5e00e2f

Please sign in to comment.