File size: 1,247 Bytes
9b546e3
 
4f3395e
 
9b546e3
 
4f3395e
 
9b546e3
4f3395e
 
 
9b546e3
4f3395e
 
 
 
 
 
 
 
 
9b546e3
 
 
 
4f3395e
9b546e3
 
 
4f3395e
 
9b546e3
 
 
 
4f3395e
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
#!/bin/bash

set -e

cd /app/api

if [[ "${MIGRATION_ENABLED}" == "true" ]]; then
  echo "Running migrations"
  poetry run flask db upgrade
fi

if [[ "${MODE}" == "worker" ]]; then
  # Get the number of available CPU cores
  if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then
    AVAILABLE_CORES=$(nproc)
    MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES}
    MIN_WORKERS=${CELERY_MIN_WORKERS:-1}
    CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}"
  else
    CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}"
  fi

  exec poetry run celery -A app.celery worker \
    -P ${CELERY_WORKER_CLASS:-gevent} \
    $CONCURRENCY_OPTION \
    --loglevel ${LOG_LEVEL} \
    -Q ${CELERY_QUEUES:-dataset,mail,ops_trace,app_deletion}

elif [[ "${MODE}" == "beat" ]]; then
  exec poetry run celery -A app.celery beat --loglevel ${LOG_LEVEL}
else
  if [[ "${DEBUG}" == "true" ]]; then
    exec poetry run flask run \
      --host=${DIFY_BIND_ADDRESS:-0.0.0.0} \
      --port=7860 \
      --debug
  else
    exec poetry run gunicorn \
      --bind "0.0.0.0:7860" \
      --workers ${SERVER_WORKER_AMOUNT:-1} \
      --worker-class ${SERVER_WORKER_CLASS:-gevent} \
      --timeout ${GUNICORN_TIMEOUT:-200} \
      --preload \
      app:app
  fi
fi