Skip to content

Commit

Permalink
[FIX] Task using correct db sevice name
Browse files Browse the repository at this point in the history
  • Loading branch information
josep-tecnativa committed Jan 29, 2025
1 parent 9174291 commit b2cff08
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tasks_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
PROJECT_ROOT = Path(__file__).parent.absolute()
SRC_PATH = PROJECT_ROOT / "odoo" / "custom" / "src"

_key = os.environ.get("_key", "")
DB_SERVICE = os.environ.get("DB_HOST", f"{_key}-db")
_key = os.environ.get("_key", "").strip()
DB_SERVICE = os.environ.get("DB_HOST") or (_key + "-db" if _key else "db")

UID_ENV = {
"GID": os.environ.get("DOODBA_GID", str(os.getgid())),
Expand Down Expand Up @@ -987,7 +987,9 @@ def snapshot(
if not destination_db:
destination_db = f"{source_db}-{datetime.now().strftime('%Y_%m_%d-%H_%M')}"
with c.cd(str(PROJECT_ROOT)):
cur_state = c.run(f"{DOCKER_COMPOSE_CMD} stop odoo db", pty=True).stdout
cur_state = c.run(
f"{DOCKER_COMPOSE_CMD} stop odoo {DB_SERVICE}", pty=True
).stdout
_logger.info("Snapshoting current %s DB to %s", (source_db, destination_db))
_run = f"{DOCKER_COMPOSE_CMD} run --rm -l traefik.enable=false odoo"
c.run(
Expand All @@ -997,7 +999,7 @@ def snapshot(
)
if "Stopping" in cur_state:
# Restart services if they were previously active
c.run(f"{DOCKER_COMPOSE_CMD} start odoo db", pty=True)
c.run(f"{DOCKER_COMPOSE_CMD} start odoo {DB_SERVICE}", pty=True)


@task(
Expand All @@ -1018,7 +1020,9 @@ def restore_snapshot(
Uses click-odoo-copydb behind the scenes to restore a DB snapshot.
"""
with c.cd(str(PROJECT_ROOT)):
cur_state = c.run(f"{DOCKER_COMPOSE_CMD} stop odoo db", pty=True).stdout
cur_state = c.run(
f"{DOCKER_COMPOSE_CMD} stop odoo {DB_SERVICE}", pty=True
).stdout
if not snapshot_name:
# List DBs
res = c.run(
Expand Down Expand Up @@ -1059,4 +1063,4 @@ def restore_snapshot(
pty=True,
)
if "Stopping" in cur_state:
c.run(f"{DOCKER_COMPOSE_CMD} start odoo db", pty=True)
c.run(f"{DOCKER_COMPOSE_CMD} start odoo {DB_SERVICE}", pty=True)

0 comments on commit b2cff08

Please sign in to comment.