Skip to content

Commit

Permalink
fix: allow gunicorn auto-reload locally
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Dec 7, 2023
1 parent 6362185 commit a1ffa44
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ POSTGRES_HOST=postgres
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_EXPOSE=127.0.0.1:5432
# Expose postgres on localhost for dev
# POSTGRES_EXPOSE=127.0.0.1:5432

# Triton ML inference server
TRITON_HOST=triton
Expand Down Expand Up @@ -84,4 +85,8 @@ FASTTEXT_MODEL_DIR=./models
# Enable/disable MongoDB access. All insights/predictions are checked
# against MongoDB, we disable by default locally to be able to easily test
# image import
ENABLE_MONGODB_ACCESS=0
ENABLE_MONGODB_ACCESS=0

# gunicorn --auto-reload is not compatible with preload_app
# so it has to be disabled when developing, to allow hot reload
GUNICORN_PRELOAD_APP=0
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ RUN \
mkdir -p /opt/robotoff/gh_pages /opt/robotoff/doc /opt/robotoff/.cov && \
chown -R off:off /opt/robotoff/gh_pages /opt/robotoff/doc /opt/robotoff/.cov
USER off
CMD [ "gunicorn", "--reload", "--config /opt/robotoff/gunicorn.py", "--log-file=-", "robotoff.app.api:api"]

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ x-robotoff-base-env:
ROBOTOFF_TLD:
ROBOTOFF_SCHEME:
STATIC_DOMAIN:
GUNICORN_PRELOAD_APP:
GUNICORN_NUM_WORKERS:
ROBOTOFF_UPDATED_PRODUCT_WAIT:
REDIS_HOST:
Expand Down
5 changes: 4 additions & 1 deletion gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
# we have a trade-off with memory vs cpu numbers
workers = int(os.environ.get("GUNICORN_NUM_WORKERS", 4))
worker_connections = 1000
preload_app = True
# gunicorn --auto-reload is not compatible with preload_app
# so it has to be disabled when developing
# Default to True (production) if not specified
preload_app = bool(os.environ.get("GUNICORN_PRELOAD_APP", True))
timeout = 60

0 comments on commit a1ffa44

Please sign in to comment.