fix(import): decouple scan from HTTP connection, prevent duplicate imports

- Add scan_manager: background asyncio task + Redis event store so scans
  survive UI navigation; SSE stream reads from Redis and is reconnectable
- Replace SSE-tied scan endpoint with POST /nc-scan/start + GET /nc-scan/stream
- Fix frontend: AbortController + useEffect cleanup cancels stream on unmount
  without stopping the server-side scan
- Add unique constraint on audio_versions.nc_file_path (migration 0009) to
  prevent duplicate imports from concurrent scans; handle IntegrityError
  gracefully in nc_scan with rollback + skip
- Fix API health check: use plain python instead of uv (not in dev image)
- Optimize Taskfile: fix duplicate dev:restart, add dev:fresh/dev:rebuild/
  dev:status, migrate uses run --rm, check includes typecheck

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mistral Vibe
2026-04-12 22:35:55 +02:00
parent b2d6b4d113
commit 15bc51603b
8 changed files with 349 additions and 147 deletions

View File

@@ -3,28 +3,76 @@ version: "3"
vars:
COMPOSE: docker compose
DEV_FLAGS: -f docker-compose.yml -f docker-compose.dev.yml
INFRA_SERVICES: db redis
APP_SERVICES: api audio-worker nc-watcher
DEV_SERVICES: db redis api web audio-worker nc-watcher
# ── Production ────────────────────────────────────────────────────────────────
# ── Development ───────────────────────────────────────────────────────────────
tasks:
help:
desc: Show available tasks
dev:up:
desc: "Start full dev environment and follow logs (recommended)"
cmds:
- echo "Available tasks:"
- echo " dev:up - Start complete development server (recommended)"
- echo " dev:build - Build development containers"
- echo " dev:clean - Safe cleanup (preserves network)"
- echo " dev:nuke - Full cleanup (removes everything)"
- echo " dev:restart - Restart development services"
- echo " dev:down - Stop development environment"
- echo " dev:logs - Follow logs from all services"
- echo " api:logs - Follow API service logs"
- echo " web:logs - Follow Web service logs"
- echo " db:migrate - Run database migrations"
- echo " db:seed - Seed database with test data"
- echo " test:e2e - Run end-to-end tests"
- echo " test:unit - Run unit tests"
- echo "Starting services..."
- "{{.COMPOSE}} {{.DEV_FLAGS}} up -d --wait {{.DEV_SERVICES}}"
- echo "All services healthy. Following logs... (Ctrl+C to stop)"
- "{{.COMPOSE}} {{.DEV_FLAGS}} logs -f api web audio-worker nc-watcher"
dev:down:
desc: "Stop all dev services"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} down"
dev:restart:
desc: "Restart one service or all (e.g. task dev:restart SERVICE=api)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} restart {{if .SERVICE}}{{.SERVICE}}{{else}}{{.DEV_SERVICES}}{{end}}"
dev:rebuild:
desc: "Rebuild and restart one service (e.g. task dev:rebuild SERVICE=api)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} up -d --build --wait {{.SERVICE}}"
dev:build:
desc: "Rebuild all dev images (run after dependency changes)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} build api web audio-worker nc-watcher"
dev:fresh:
desc: "Wipe volumes, rebuild all images, and start clean"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} down -v"
- "{{.COMPOSE}} {{.DEV_FLAGS}} build api web audio-worker nc-watcher"
- task: dev:up
dev:clean:
desc: "Stop services and remove volumes (preserves images)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} down -v"
dev:nuke:
desc: "Full cleanup — removes containers, volumes, images, and build cache"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} down -v --rmi local"
- docker system prune -f
dev:status:
desc: "Show status of all dev services"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} ps"
dev:logs:
desc: "Follow dev logs (all services, or pass SERVICE=api)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} logs -f {{.SERVICE}}"
dev:web:
desc: "Run Vite dev server locally with HMR (run alongside dev:up)"
dir: web
cmds:
- npm run dev
# ── Production ────────────────────────────────────────────────────────────────
up:
desc: Start all services (production)
@@ -32,18 +80,12 @@ tasks:
- "{{.COMPOSE}} up -d"
down:
desc: Stop all services
desc: Stop all services (production)
cmds:
- "{{.COMPOSE}} down"
build:
desc: Build all images
cmds:
- task: check
- "{{.COMPOSE}} build"
logs:
desc: Follow logs for all services (pass SERVICE= to filter)
desc: Follow logs (pass SERVICE= to filter)
cmds:
- "{{.COMPOSE}} logs -f {{.SERVICE}}"
@@ -52,82 +94,23 @@ tasks:
cmds:
- "{{.COMPOSE}} restart {{.SERVICE}}"
# ── Dev / Debug ───────────────────────────────────────────────────────────────
dev:
desc: Start backend in dev mode (hot reload, source mounts)
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} up {{.DEV_SERVICES}}"
dev:detach:
desc: Start backend in dev mode, detached
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} up -d {{.DEV_SERVICES}}"
dev:web:
desc: Start Vite dev server (proxies /api to localhost:8000)
dir: web
cmds:
- npm run dev
dev:up:
desc: Start complete development server (recommended)
cmds:
- echo "Starting development environment..."
- "{{.COMPOSE}} {{.DEV_FLAGS}} up -d {{.DEV_SERVICES}}"
- echo "Following logs... (Ctrl+C to stop)"
- "{{.COMPOSE}} {{.DEV_FLAGS}} logs -f api web audio-worker nc-watcher"
dev:build:
desc: Build development containers (only when dependencies change)
cmds:
- echo "Building development containers..."
- "{{.COMPOSE}} {{.DEV_FLAGS}} build --pull api web"
- echo "Containers built successfully"
dev:logs:
desc: Follow logs in dev mode
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} logs -f {{.SERVICE}}"
dev:restart:
desc: Restart a service in dev mode (e.g. task dev:restart SERVICE=audio-worker)
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} restart {{.SERVICE}}"
dev:clean:
desc: Safe cleanup (preserves network/proxy, removes containers/volumes)
cmds:
- echo "Stopping development services..."
- "{{.COMPOSE}} {{.DEV_FLAGS}} down"
- echo "Removing development volumes..."
- docker volume rm -f $(docker volume ls -q | grep rehearsalhub) || true
- echo "Development environment cleaned (network preserved)"
dev:nuke:
desc: Full cleanup (removes everything including network - use when network is corrupted)
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} down -v"
- docker system prune -f --volumes
dev:restart:
desc: Restart development services (preserves build cache)
cmds:
- echo "Restarting development services..."
- "{{.COMPOSE}} {{.DEV_FLAGS}} restart {{.DEV_SERVICES}}"
- echo "Services restarted"
# ── Database ──────────────────────────────────────────────────────────────────
migrate:
desc: Run Alembic migrations
desc: Run Alembic migrations (works whether or not the API container is running)
cmds:
- "{{.COMPOSE}} exec api alembic upgrade head"
- "{{.COMPOSE}} {{.DEV_FLAGS}} run --rm --no-deps api alembic upgrade head"
migrate:auto:
desc: Autogenerate a migration (e.g. task migrate:auto M="add users table")
cmds:
- "{{.COMPOSE}} exec api alembic revision --autogenerate -m '{{.M}}'"
- "{{.COMPOSE}} {{.DEV_FLAGS}} run --rm --no-deps api alembic revision --autogenerate -m '{{.M}}'"
db:reset:
desc: "Drop and recreate schema (dev only — destroys all data)"
cmds:
- "{{.COMPOSE}} {{.DEV_FLAGS}} run --rm --no-deps api alembic downgrade base"
- "{{.COMPOSE}} {{.DEV_FLAGS}} run --rm --no-deps api alembic upgrade head"
# ── Setup ─────────────────────────────────────────────────────────────────────
@@ -142,18 +125,16 @@ tasks:
# ── Testing ───────────────────────────────────────────────────────────────────
# Run this after every feature branch — fast, no external services required.
test:feature:
desc: "Post-feature pipeline: typecheck + frontend tests + backend unit tests (no services needed)"
desc: "Fast post-feature check: typecheck + frontend + backend unit tests (no services needed)"
cmds:
- task: typecheck:web
- task: lint
- task: test:web
- task: test:api:unit
- task: test:worker
- task: test:watcher
# Full CI pipeline — runs everything including integration tests.
# Requires: services up (task dev:detach), DB migrated.
ci:
desc: "Full CI pipeline: lint + typecheck + all tests (requires services running)"
cmds:
@@ -169,11 +150,10 @@ tasks:
deps: [test:api, test:worker, test:watcher]
test:web:
desc: Run frontend unit tests (via podman — no local Node required)
desc: Run frontend unit tests
dir: web
cmds:
- podman run --rm -v "$(pwd)":/app:Z -w /app node:20-alpine
sh -c "npm install --legacy-peer-deps --silent && npm run test"
- npm run test
test:api:
desc: Run all API tests with coverage (unit + integration)
@@ -209,7 +189,9 @@ tasks:
check:
desc: Run all linters and type checkers
deps: [lint]
cmds:
- task: lint
- task: typecheck:web
lint:
desc: Lint all services
@@ -226,7 +208,7 @@ tasks:
- npm run typecheck
format:
desc: Auto-format Python source
desc: Auto-format all Python source
cmds:
- cd api && uv run ruff format src/ tests/
- cd worker && uv run ruff format src/ tests/
@@ -238,29 +220,29 @@ tasks:
desc: Shell into the API container
interactive: true
cmds:
- "{{.COMPOSE}} exec api bash"
- "{{.COMPOSE}} {{.DEV_FLAGS}} exec api bash"
shell:db:
desc: psql shell
desc: Open a psql shell
interactive: true
cmds:
- "{{.COMPOSE}} exec db psql -U $POSTGRES_USER -d $POSTGRES_DB"
- "{{.COMPOSE}} {{.DEV_FLAGS}} exec db psql -U ${POSTGRES_USER:-rh_user} -d ${POSTGRES_DB:-rehearsalhub}"
shell:redis:
desc: redis-cli shell
desc: Open a redis-cli shell
interactive: true
cmds:
- "{{.COMPOSE}} exec redis redis-cli"
- "{{.COMPOSE}} {{.DEV_FLAGS}} exec redis redis-cli"
# ── Container Build & Release ──────────────────────────────────────────────
# ── Container Build & Release ─────────────────────────────────────────────────
build:containers:
desc: Build all container images with current git tag
build:
desc: Build all production images
cmds:
- bash scripts/build-containers.sh
push:containers:
desc: Push all container images to Gitea registry
push:
desc: Push all container images to the registry
cmds:
- bash scripts/upload-containers-simple.sh