From a4e8fcbed2d26b92f104d90899c2491634e2ee36 Mon Sep 17 00:00:00 2001 From: Sami Nouidri Date: Mon, 13 Oct 2025 09:39:10 +0200 Subject: [PATCH] PB-1992 : Add gunicorn keepalive env var --- README.md | 1 + app/settings.py | 2 ++ wsgi.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index de774b7..de9aa1a 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,4 @@ The service is configured by Environment Variable: | GUNICORN_TMPFS_DIR | `None` |The working directory for the gunicorn workers. | | WSGI_WORKERS | `2` | The number of workers per CPU. | | UNLISTED_ICON_SETS | | Comma separated list of icon set to un-list. Those sets won't be listed in the /sets endpoint. | +| GUNICORN_KEEPALIVE | `2` | The [`keepalive`](https://docs.gunicorn.org/en/stable/settings.html#keepalive) setting passed to gunicorn. | diff --git a/app/settings.py b/app/settings.py index e098f37..5badb00 100644 --- a/app/settings.py +++ b/app/settings.py @@ -28,6 +28,8 @@ os.environ['LOGS_DIR'] = LOGS_DIR # Set default if not set LOGGING_CFG = os.getenv('LOGGING_CFG', 'logging-cfg-local.yml') +GUNICORN_KEEPALIVE = int(os.getenv('GUNICORN_KEEPALIVE', '2')) + # Definition of the allowed domains for CORS implementation ALLOWED_DOMAINS = os.getenv('ALLOWED_DOMAINS', r'.*').split(',') CACHE_CONTROL = os.getenv('CACHE_CONTROL', 'public, max-age=86400') diff --git a/wsgi.py b/wsgi.py index e08e49e..62b73cc 100644 --- a/wsgi.py +++ b/wsgi.py @@ -4,6 +4,7 @@ from app import app as application from app.helpers import get_logging_cfg +from app.settings import GUNICORN_KEEPALIVE class StandaloneApplication(BaseApplication): # pylint: disable=abstract-method @@ -36,6 +37,7 @@ def load(self): 'workers': int(os.getenv('WSGI_WORKERS', '2')), # scaling horizontally is left to Kubernetes 'timeout': int(os.getenv('WSGI_TIMEOUT', '5')), + 'keepalive': GUNICORN_KEEPALIVE, 'logconfig_dict': get_logging_cfg(), 'forwarded_allow_ips': os.getenv('FORWARED_ALLOW_IPS', '*'), 'secure_scheme_headers': {