Underground-Digital/Workflow-Engine
0
1#!/bin/bash2 3set -e4 5if [[ "${MIGRATION_ENABLED}" == "true" ]]; then6 echo "Running migrations"7 flask upgrade-db8fi9 10if [[ "${MODE}" == "worker" ]]; then11 12 # Get the number of available CPU cores13 if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then14 # Set MAX_WORKERS to the number of available cores if not specified15 AVAILABLE_CORES=$(nproc)16 MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}17 MIN_WORKERS=${CELERY_MIN_WORKERS:-1}18 CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"19 else20 CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"21 fi22 23 exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION --loglevel ${LOG_LEVEL} \24 -Q ${CELERY_QUEUES:-dataset,generation,mail,ops_trace,app_deletion}25 26elif [[ "${MODE}" == "beat" ]]; then27 exec celery -A app.celery beat --loglevel ${LOG_LEVEL}28else29 if [[ "${DEBUG}" == "true" ]]; then30 exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debug31 else32 exec gunicorn \33 --bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \34 --workers ${SERVER_WORKER_AMOUNT:-1} \35 --worker-class ${SERVER_WORKER_CLASS:-gevent} \36 --timeout ${GUNICORN_TIMEOUT:-200} \37 --preload \38 app:app39 fi40fi41 