Skip to content

Commit c71fcda

Browse files
committed
Add Gunicorn configuration.
1 parent d8706c9 commit c71fcda

File tree

8 files changed

+94
-4
lines changed

8 files changed

+94
-4
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $(VIRTUAL_ENV):
3232

3333
.PHONY: run
3434
run: env
35-
$(LOCAL_PYTHON) -m gunicorn -w 4 wsgi:app
35+
$(LOCAL_PYTHON) -m gunicorn --config=gunicorn.conf.py
3636

3737
.PHONY: install
3838
install: env

config.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Config:
1717
FLASK_APP = "wsgi.py"
1818
SECRET_KEY = environ.get("SECRET_KEY")
1919
FLASK_DEBUG = environ.get("FLASK_DEBUG")
20+
SOCK_SERVER_OPTIONS = {"ping_interval": 25}
2021

2122
# Flask-Assets
2223
LESS_BIN = environ.get("LESS_BIN")

flask_assets_tutorial/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def create_app():
1515

1616
with app.app_context():
1717
# Import parts of our flask_assets_tutorial
18-
from .admin import admin_routes
18+
from .admin import routes as admin_routes
1919
from .assets import compile_static_assets, compile_stylesheet_bundles
20-
from .main import main_routes
20+
from .main import routes as main_routes
2121

2222
# Register Blueprints
2323
app.register_blueprint(admin_routes.admin_blueprint)

gunicorn.conf.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Gunicorn configuration file."""
2+
import socket
3+
4+
from config import Config
5+
6+
proc_name = "flaskassets"
7+
wsgi_app = "wsgi:app"
8+
bind = "unix:flask.sock"
9+
threads = 4
10+
workers = 2
11+
12+
if Config.ENVIRONMENT == "development":
13+
reload = True
14+
workers = 1
15+
threads = 1
16+
17+
18+
if Config.ENVIRONMENT == "production":
19+
daemon = True
20+
accesslog = "/var/log/flaskassets/access.log"
21+
errorlog = "/var/log/flaskassets/error.log"
22+
loglevel = "trace"
23+
dogstatsd_tags = [
24+
"env:prod",
25+
f"host:{socket.gethostbyname(socket.gethostname())}",
26+
"service:flaskassets",
27+
"language:python",
28+
]

poetry.lock

+61-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pytest = "*"
2323
black = "*"
2424
isort = "*"
2525
gunicorn = "*"
26+
flask-sock = "^0.7.0"
2627

2728
[tool.poetry.scripts]
2829
run = "wsgi:app"

0 commit comments

Comments
 (0)