Merge: promote dev to prod
This commit is contained in:
commit
a97578d815
3 changed files with 30 additions and 0 deletions
|
|
@ -76,6 +76,26 @@ def _parse_upload_date(raw) -> date | None:
|
|||
|
||||
# --- claim + recovery -----------------------------------------------------------------------
|
||||
|
||||
def _wait_for_schema(timeout: float = 300.0) -> None:
|
||||
"""Block until the download tables exist before doing any DB work.
|
||||
|
||||
The API applies migrations on its OWN startup, and the worker is a separate container that may
|
||||
boot first (they start in parallel). Without this, the worker would hit a missing `download_jobs`
|
||||
table and crash-loop until the API's migrations land. Poll patiently instead."""
|
||||
deadline = time.monotonic() + timeout
|
||||
while not _stop.is_set():
|
||||
try:
|
||||
with SessionLocal() as db:
|
||||
db.execute(text("SELECT 1 FROM download_jobs LIMIT 1"))
|
||||
return
|
||||
except Exception as exc: # noqa: BLE001 — table not migrated yet / DB not up yet
|
||||
if time.monotonic() > deadline:
|
||||
log.warning("download schema still absent after %ss; continuing: %s", timeout, str(exc)[:120])
|
||||
return
|
||||
log.info("waiting for the database schema (API migrations)…")
|
||||
_stop.wait(3.0)
|
||||
|
||||
|
||||
def _recover_orphans() -> None:
|
||||
"""Reset state left behind by a previous crash so nothing is stuck."""
|
||||
with SessionLocal() as db:
|
||||
|
|
@ -573,6 +593,9 @@ def main() -> None:
|
|||
log.info("WORKER_ENABLED is off; worker exiting (nothing to do).")
|
||||
return
|
||||
|
||||
_wait_for_schema() # the API may still be applying migrations when we boot
|
||||
if _stop.is_set():
|
||||
return
|
||||
_recover_orphans()
|
||||
n = max(1, settings.download_worker_concurrency)
|
||||
log.info("Download worker started (concurrency=%d, root=%s).", n, settings.download_root)
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ services:
|
|||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
# Start only after the API is healthy (it applies the DB migrations on startup), so the
|
||||
# download tables exist before the worker touches them.
|
||||
api:
|
||||
condition: service_healthy
|
||||
bgutil-pot:
|
||||
condition: service_started
|
||||
networks: [internal]
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ services:
|
|||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
# Start only after the API is healthy (it applies the DB migrations on startup).
|
||||
api:
|
||||
condition: service_healthy
|
||||
bgutil-pot:
|
||||
condition: service_started
|
||||
volumes:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue