Skip to content

Commit

Permalink
Better show migrations error log (#59)
Browse files Browse the repository at this point in the history
* Better show migrations error log

* Small import cleanup
  • Loading branch information
omar-selo authored Nov 2, 2023
1 parent 5b6e7f4 commit 3358d9c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions backend/charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from charms.nginx_ingress_integrator.v0.nginx_route import require_nginx_route
from ops.charm import CharmBase
from ops.main import main
from ops.model import ActiveStatus, MaintenanceStatus, WaitingStatus
from ops.pebble import Layer
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus
from ops.pebble import Layer, ExecError
from requests import get

# Log messages can be retrieved using juju debug-log
Expand Down Expand Up @@ -80,11 +80,14 @@ def _migrate_database(self):
environment=self._postgres_relation_data(),
)

stdout, _ = process.wait_output()

logger.info(stdout)

self.unit.status = ActiveStatus()
try:
stdout, _ = process.wait_output()
logger.info(stdout)
self.unit.status = ActiveStatus()
except ExecError as e:
logger.error(e.stdout)
logger.error(e.stderr)
self.unit.status = BlockedStatus("Database migration failed")

def _on_database_changed(self, event):
self._migrate_database()
Expand Down Expand Up @@ -134,9 +137,7 @@ def _app_environment(self):
"""
This creates a dictionary of environment variables needed by the application
"""
env = {
"SENTRY_DSN": self.config["sentry_dsn"]
}
env = {"SENTRY_DSN": self.config["sentry_dsn"]}
env.update(self._postgres_relation_data())
return env

Expand Down

0 comments on commit 3358d9c

Please sign in to comment.