From 2db3ce6c2e91b81a64916eba47ae34f4d9182702 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 7 Apr 2018 10:10:47 +0100 Subject: Don't create tables on route load by default. * If "FLASK_DEBUG" is in your env vars, tables will be created on route load * If you run a query against a table not declared in database.py, a warning is emitted --- gunicorn_config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 gunicorn_config.py (limited to 'gunicorn_config.py') diff --git a/gunicorn_config.py b/gunicorn_config.py new file mode 100644 index 00000000..7e17b0cc --- /dev/null +++ b/gunicorn_config.py @@ -0,0 +1,12 @@ +# coding=utf-8 +def when_ready(_server): + """ server hook that only runs when the gunicorn master process loads """ + + print("Creating tables...") + + from pysite.database import RethinkDB + + db = RethinkDB(loop_type=None) + created = db.create_tables() + + print(f"Created {created} tables.") -- cgit v1.2.3 From c43b15ce0727842e1388c0b6facefc3f7e73839c Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 7 Apr 2018 10:43:35 +0100 Subject: Fix logging in gunicorn_config --- gunicorn_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gunicorn_config.py') diff --git a/gunicorn_config.py b/gunicorn_config.py index 7e17b0cc..e4b66135 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,12 +1,12 @@ # coding=utf-8 -def when_ready(_server): +def when_ready(server): """ server hook that only runs when the gunicorn master process loads """ - print("Creating tables...") + server.log.info("Creating tables...") from pysite.database import RethinkDB db = RethinkDB(loop_type=None) created = db.create_tables() - print(f"Created {created} tables.") + server.log.info(f"Created {created} tables.") -- cgit v1.2.3 From 886fb0b06117e56cc70767424b718c90e2789ef4 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sun, 8 Apr 2018 01:13:26 +0100 Subject: Fix build --- .travis.yml | 1 + gunicorn_config.py | 15 ++++++++++++--- templates/main/navigation.html | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'gunicorn_config.py') diff --git a/.travis.yml b/.travis.yml index 284ec24f..95fdcfc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ install: - pip install -r requirements-ci.txt script: - flake8 + - python gunicorn_config.py - py.test app_test.py --cov pysite --cov-report term-missing -v - coveralls after_success: diff --git a/gunicorn_config.py b/gunicorn_config.py index e4b66135..eb2f6e1b 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,12 +1,21 @@ # coding=utf-8 -def when_ready(server): +def when_ready(server=None): """ server hook that only runs when the gunicorn master process loads """ - server.log.info("Creating tables...") + if server: + output = server.log.info + else: + output = print + + output("Creating tables...") from pysite.database import RethinkDB db = RethinkDB(loop_type=None) created = db.create_tables() - server.log.info(f"Created {created} tables.") + output(f"Created {created} tables.") + + +if __name__ == "__main__": + when_ready() diff --git a/templates/main/navigation.html b/templates/main/navigation.html index 19322c65..47c20d56 100644 --- a/templates/main/navigation.html +++ b/templates/main/navigation.html @@ -39,7 +39,7 @@
  •  Login with Discord
  • {% endif %} {% else %} -
  •  Debug mode
  • +
  •  Debug mode
  • {% endif %} {% if current_page.startswith("info") %} -- cgit v1.2.3 From cf983a363514cb0d5c19c12ab942c0795b286682 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sun, 8 Apr 2018 01:13:55 +0100 Subject: Fix build for real --- app_test.py | 3 +++ gunicorn_config.py | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'gunicorn_config.py') diff --git a/app_test.py b/app_test.py index 5747dbd6..5bb84945 100644 --- a/app_test.py +++ b/app_test.py @@ -5,8 +5,11 @@ from flask import Blueprint from flask_testing import TestCase from app import manager +from gunicorn_config import when_ready from pysite.constants import DISCORD_OAUTH_REDIRECT, DISCORD_OAUTH_AUTHORIZED +when_ready() + manager.app.tests_blueprint = Blueprint("tests", __name__) manager.load_views(manager.app.tests_blueprint, "pysite/views/tests") manager.app.register_blueprint(manager.app.tests_blueprint) diff --git a/gunicorn_config.py b/gunicorn_config.py index eb2f6e1b..f863edd4 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -15,7 +15,3 @@ def when_ready(server=None): created = db.create_tables() output(f"Created {created} tables.") - - -if __name__ == "__main__": - when_ready() -- cgit v1.2.3