Skip to content

Commit

Permalink
Create tables only on process zero; do not add tables in production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Dec 11, 2020
1 parent 04987bb commit 9eb770c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions template_app/app_server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import tornado.web

from baselayer.app import models, model_util
from baselayer.app.app_server import (handlers as baselayer_handlers,
settings as baselayer_settings)
from baselayer.app.config import load_config


from .handlers.example_computation import ExampleComputationHandler
from .handlers.push_notification import PushNotificationHandler


def make_app(cfg, baselayer_handlers, baselayer_settings):
def make_app(
cfg, baselayer_handlers, baselayer_settings, process=None, env=None
):
"""Create and return a `tornado.web.Application` object with specified
handlers and settings.
Expand All @@ -23,6 +21,11 @@ def make_app(cfg, baselayer_handlers, baselayer_settings):
Tornado handlers needed for baselayer to function.
baselayer_settings : cfg
Settings needed for baselayer to function.
process : int
When launching multiple app servers, which number is this?
env : dict
Environment in which the app was launched. Currently only has
one key, 'debug'---true if launched with `--debug`.
"""
if cfg['cookie_secret'] == 'abc01234':
Expand All @@ -32,7 +35,7 @@ def make_app(cfg, baselayer_handlers, baselayer_settings):
print('!' * 80)

handlers = baselayer_handlers + [
# (r'/some_url(/.*)?', MyTornadoHandler),
# (r'/some_url(/.*)?', MyTornadoHandler),
(r'/example_compute', ExampleComputationHandler),
(r'/push_notification', PushNotificationHandler)
]
Expand All @@ -42,7 +45,10 @@ def make_app(cfg, baselayer_handlers, baselayer_settings):

app = tornado.web.Application(handlers, **settings)
models.init_db(**cfg['database'])
model_util.create_tables()

if process == 0:
model_util.create_tables(add=env.debug)

app.cfg = cfg

return app

0 comments on commit 9eb770c

Please sign in to comment.