#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"

source .venv/bin/activate

eval "$(
  .venv/bin/python - <<'PY'
from fastapi_admin.config import (
    LEAUDIT_WORKER_CONCURRENCY,
    LEAUDIT_WORKER_QUEUE_NORMAL,
    LEAUDIT_WORKER_QUEUE_URGENT,
)

print(f'WORKER_CONCURRENCY={LEAUDIT_WORKER_CONCURRENCY}')
print(f'WORKER_QUEUES={LEAUDIT_WORKER_QUEUE_URGENT},{LEAUDIT_WORKER_QUEUE_NORMAL}')
PY
)"

WORKER_NODE_NAME="leaudit_worker_${HOSTNAME:-local}_$$@%h"

celery -A fastapi_admin.celery_app:celery_app worker \
  -Q "${WORKER_QUEUES}" \
  -n "${WORKER_NODE_NAME}" \
  --concurrency="${WORKER_CONCURRENCY}" \
  --loglevel=INFO
