fix bd
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
"""Worker entrypoint: runs trigger checker + future background jobs."""
|
||||
"""Worker entrypoint: runs trigger checker + future background jobs.
|
||||
|
||||
Waits for the database (and required tables) to be ready before starting
|
||||
the background loops. This prevents the worker from crashing when the
|
||||
backend hasn't finished running `init_db()` yet (typical docker-compose
|
||||
race condition where both services start in parallel).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from app.db_wait import wait_for_db_or_exit
|
||||
from app.logging_setup import get_logger, setup_logging
|
||||
from app.workers.trigger_runner import main_loop as trigger_loop
|
||||
|
||||
@@ -12,6 +19,13 @@ log = get_logger("worker")
|
||||
async def main():
|
||||
setup_logging()
|
||||
log.info("worker_starting")
|
||||
|
||||
# Wait until DB is reachable and the `settings` table exists.
|
||||
# The backend's lifespan runs `init_db()` which creates tables; if the
|
||||
# worker comes up first, this loop will retry until that completes.
|
||||
await wait_for_db_or_exit(max_retries=60, delay=2.0)
|
||||
|
||||
log.info("worker_db_ready_starting_loops")
|
||||
# Run all background loops concurrently
|
||||
await asyncio.gather(
|
||||
trigger_loop(),
|
||||
|
||||
Reference in New Issue
Block a user