File size: 998 Bytes
3533fb9
 
 
02c1fe3
 
 
 
 
 
 
 
 
 
 
 
 
3533fb9
 
 
cbf7ff4
3533fb9
 
 
 
 
 
02c1fe3
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
set -e

# Size HTTP workers for the Space CPU tier (clamp 2–4).
# Override with WEB_CONCURRENCY if needed.
CORES=$(nproc 2>/dev/null || echo 2)
if [ -n "${WEB_CONCURRENCY:-}" ]; then
  WORKERS="$WEB_CONCURRENCY"
elif [ "$CORES" -le 1 ]; then
  WORKERS=2
elif [ "$CORES" -ge 4 ]; then
  WORKERS=4
else
  WORKERS="$CORES"
fi

echo "Starting Celery worker in background..."
celery -A app.worker.celery_app worker \
    --loglevel=info \
    --concurrency=1 \
    --pool=solo &

echo "Starting Celery beat scheduler in background..."
celery -A app.worker.celery_app beat \
    --loglevel=info &

echo "Starting FastAPI via gunicorn (${WORKERS} uvicorn workers, $(nproc 2>/dev/null || echo '?') CPU cores)..."
exec gunicorn main:app \
    --worker-class uvicorn.workers.UvicornWorker \
    --workers "$WORKERS" \
    --bind "0.0.0.0:${PORT:-7860}" \
    --timeout 120 \
    --graceful-timeout 30 \
    --keep-alive 5 \
    --access-logfile - \
    --error-logfile - \
    --log-level info