#!/bin/bash

set -e

if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
  echo "Running migrations"
  alembic upgrade head
fi

if [[ "${MODE}" == "worker" ]]; then
  echo "celery run"
  #pip list
  celery -A worker.celery_app worker -c ${CELERY_WORKERS:-1} -l INFO
else
  echo "uvicorn run"
  #uvicorn main:app --host 0.0.0.0 --port 8086 --workers ${APP_SERVER_WORKERS:-1}
  #poetry run gunicorn -c gunicorn_config.py main:app
  gunicorn -w 4 -t ${APP_SERVER_WORKERS:-1} -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8086 --threads 20 main:app
fi
