Skip to content

Commit

Permalink
Charm now happily works with multiple units
Browse files Browse the repository at this point in the history
  • Loading branch information
mz2 committed Dec 12, 2023
1 parent 2558fed commit 567d6b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/charm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
venv
prime
stage
parts
9 changes: 5 additions & 4 deletions backend/charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import logging

from data_platform_libs.v0.data_interfaces import DatabaseRequires
from charms.data_platform_libs.v0.data_interfaces import DatabaseRequires
from charms.nginx_ingress_integrator.v0.nginx_route import require_nginx_route
from faults import UnitReadinessFault
from nginx_ingress_integrator.v0.nginx_route import require_nginx_route
from ops import RelationChangedEvent, RelationJoinedEvent
from ops.charm import CharmBase
from ops.main import main
Expand Down Expand Up @@ -59,7 +59,7 @@ def _setup_nginx(self):
)

def _on_upgrade_charm(self, event):
self._migrate_database()
self._attempt_database_migration()

def _attempt_database_migration(self) -> bool | UnitReadinessFault:
"""Return true if migrations were attempted, false if not attempted (if unit is not the leader).
Expand Down Expand Up @@ -226,7 +226,8 @@ def _pebble_layer(self) -> Layer | UnitReadinessFault:
"command": "curl --fail --silent --head http://0.0.0.0:8000/v1/version",
},
"timeout": "5s",
"period": "5s",
"period": "15s",
"override": "replace",
}
},
}
Expand Down
3 changes: 2 additions & 1 deletion backend/charm/src/faults.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class UnitReadinessFault:
"""A ReadinessFault describes the reason for a unit not to be ready."""

def __init__(self, reason: str, parent: "UnitReadinessFault" | None = None):
def __init__(self, reason: str, parent=None):
self.reason = reason
self.parent = parent

def __str__(self):
"""Build a representation by recursively traversing the fault hierarchy in reverse order."""
Expand Down

0 comments on commit 567d6b3

Please sign in to comment.