misc: Add support for WEB_CONCURRENCY environment variable

The `WEB_CONCURRENCY` environment variable is a more common way to
configure the number of workers for Gunicorn [1] or other web servers.

This change maintains `GUNICORN_WORKERS` compatibility, while notifying
users that it is deprecated and should be replaced with
`WEB_CONCURRENCY`.

It would also allow us to replace Gunicorn with another web server in
the future without changing the variable name.

[1] https://docs.gunicorn.org/en/stable/settings.html#workers
This commit is contained in:
Michael Manganiello
2025-02-19 00:16:38 -03:00
parent d24f9810f1
commit 9602d58865
3 changed files with 13 additions and 5 deletions

View File

@@ -19,12 +19,14 @@ debug_log() {
fi
}
# print debug log output if enabled
info_log() {
echo "INFO: [init][$(date +"%Y-%m-%d %T")]" "${@}" || true
}
# print error log output if enabled
warn_log() {
echo "WARNING: [init][$(date +"%Y-%m-%d %T")]" "${@}" || true
}
error_log() {
echo "ERROR: [init][$(date +"%Y-%m-%d %T")]" "${@}" || true
exit 1
@@ -45,6 +47,13 @@ start_bin_gunicorn() {
# commands to start our main application and store its PID to check for crashes
info_log "starting gunicorn"
# TODO: Remove support for GUNICORN_WORKERS in future version.
if [[ -n ${GUNICORN_WORKERS-} ]]; then
warn_log "GUNICORN_WORKERS variable is deprecated, use WEB_CONCURRENCY instead"
: "${WEB_CONCURRENCY:=${GUNICORN_WORKERS}}"
fi
gunicorn \
--access-logfile - \
--error-logfile - \
@@ -53,7 +62,7 @@ start_bin_gunicorn() {
--bind=unix:/tmp/gunicorn.sock \
--pid=/tmp/gunicorn.pid \
--forwarded-allow-ips="*" \
--workers "${GUNICORN_WORKERS:=2}" \
--workers "${WEB_CONCURRENCY:-2}" \
main:app &
}