#!/bin/bash

set -e
CORES="$(nproc)"
WORKERS=$(( 1 * "${CORES}"))  # As many workers as there are cores
TIMEOUT=10800  # 3h. We can have quite long running ML jobs. Should ideally use distributed training to cut down training time.
#WORKER_CLASS="gevent"  # Asyncronous worker - https://docs.gunicorn.org/en/stable/design.html#choosing-a-worker-type
APP_OPTS=""

WSGI_OPS=(
    "--bind=0.0.0.0:12345"
    "--workers=${WORKERS}"
    "--timeout=${TIMEOUT}"
    #"--worker-class=${WORKER_CLASS}"
)

run_wsgi(){
    exec "${@}" gunicorn "${WSGI_OPS[@]}" app:app "${APP_OPTS[@]}"
}

run_wsgi
