feat: add ARQ background worker to container

- Create app/core/worker.py with WorkerSettings for ARQ
- Register all job functions: reindex, index_*, embedding_batch, deep_analysis
- Update prestart.sh to start ARQ worker in background before uvicorn
- Worker runs with max_jobs=10, job_timeout=300s
This commit is contained in:
Agent Zero
2026-07-19 19:36:48 +02:00
parent dc24c37c19
commit f1f3ce26b3
2 changed files with 96 additions and 7 deletions
Regular → Executable
+8 -7
View File
@@ -4,15 +4,13 @@
#
# Responsibilities:
# 1. Run Alembic DB migrations (alembic upgrade head).
# 2. Start uvicorn as PID 1 (so signals like SIGTERM are forwarded correctly).
# 2. Start ARQ background worker in background.
# 3. Start uvicorn as PID 1 (so signals like SIGTERM are forwarded correctly).
#
# Notes:
# - `set -e` ensures the container crashes loudly if migrations fail,
# rather than starting a broken app on an inconsistent schema.
# - `exec uvicorn ...` replaces the shell process with uvicorn, so uvicorn
# becomes PID 1 and receives Docker's SIGTERM directly for graceful shutdown.
# - `--workers 1` is intentional for v1: SQLite (dev) is single-threaded,
# and asyncpg (prod) scales fine with one worker + an async connection pool.
# - `set -e` ensures the container crashes loudly if migrations fail.
# - ARQ worker runs in background, uvicorn becomes PID 1.
# - `--workers 1` is intentional for v1.
# =============================================================================
set -e
@@ -21,6 +19,9 @@ echo "[prestart] $(date -u +%Y-%m-%dT%H:%M:%SZ) - Running alembic upgrade head..
alembic upgrade head
echo "[prestart] DB migrations completed successfully."
echo "[prestart] Starting ARQ background worker..."
arq app.core.worker.WorkerSettings &
echo "[prestart] Starting uvicorn on 0.0.0.0:8000 (workers=1)..."
exec uvicorn app.main:app \
--host 0.0.0.0 \