#!/bin/sh
set -e

python manage.py migrate --noinput
python manage.py collectstatic --noinput

# WebSocket pushes (flash, lens, live view, pairing) between workers need a
# shared channel layer. Without Redis each worker only sees its own sockets,
# so pushes get lost at random -> run a single worker instead.
if [ -z "$REDIS_URL" ]; then
    echo "WARNING: REDIS_URL not set; realtime needs Redis for >1 worker. Using 1 worker." >&2
    export WEB_CONCURRENCY=1
else
    export WEB_CONCURRENCY="${WEB_CONCURRENCY:-3}"
fi

exec "$@"
