Skip to content

Commit

Permalink
Add gunicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
kencx committed Jun 21, 2023
1 parent d5760b9 commit 800f5d2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ check:
clean: check
- rm *.txt

run:
## run.dev: run Flask debug server
run.dev:
flask --app 'calibre_rest:create_app("dev")' run --debug

## run gunicorn server
run:
gunicorn 'calibre_rest:create_app("prod")' -c gunicorn.py

test:
pytest -v
1 change: 0 additions & 1 deletion calibre_rest/calibre.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def add_empty(self, **kwargs: Any) -> list[int]:
else:
return []

# TODO handle when passing multiple of the same flag
def _handle_add_flags(self, cmd: str, kwargs: Any):
for flag in self.ADD_FLAGS:
value = kwargs.get(flag)
Expand Down
28 changes: 28 additions & 0 deletions gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from multiprocessing import cpu_count

bind = "0.0.0.0:5000"

# Maximum number of backlog requests to hold onto before users get error messages.
backlog = 100
# workers = cpu_count() * 2 + 1
workers = 2

# Do not support persistent connections. Close after each request.
worker_class = "sync"

timeout = 30
keepalive = 2
spew = False
daemon = False
raw_env = []

pidfile = "/tmp/gunicorn_vm_api.pid"

umask = 755
user = 1000
group = 1000
tmp_upload_directory = None

# Log errors received to stdout with `-`
error_log = "-"
access_log = "-"
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
jsonschema
gunicorn
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ flask==2.3.2 \
--hash=sha256:77fd4e1249d8c9923de34907236b747ced06e5467ecac1a7bb7115ae0e9670b0 \
--hash=sha256:8c2f9abd47a9e8df7f0c3f091ce9497d011dc3b31effcf4c85a6e2b50f4114ef
# via -r requirements.in
gunicorn==20.1.0 \
--hash=sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e \
--hash=sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8
# via -r requirements.in
itsdangerous==2.1.2 \
--hash=sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44 \
--hash=sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a
Expand Down Expand Up @@ -119,3 +123,7 @@ werkzeug==2.3.6 \
--hash=sha256:935539fa1413afbb9195b24880778422ed620c0fc09670945185cce4d91a8890 \
--hash=sha256:98c774df2f91b05550078891dee5f0eb0cb797a522c757a2452b9cee5b202330
# via flask

# WARNING: The following packages were not pinned, but pip requires them to be
# pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag.
# setuptools

0 comments on commit 800f5d2

Please sign in to comment.