Explicitly pass settings for flask into flask app factory (#750)

This commit is contained in:
Brett Sun 2016-11-15 17:41:35 +01:00 committed by GitHub
parent 2fd6cc332b
commit 786635df4a
2 changed files with 9 additions and 5 deletions

View File

@ -49,19 +49,22 @@ class StandaloneApplication(gunicorn.app.base.BaseApplication):
return self.application return self.application
def create_app(settings): def create_app(*, debug=False, threads=4):
"""Return an instance of the Flask application. """Return an instance of the Flask application.
Args: Args:
debug (bool): a flag to activate the debug mode for the app debug (bool): a flag to activate the debug mode for the app
(default: False). (default: False).
threads (int): number of threads to use
Return:
an instance of the Flask application.
""" """
app = Flask(__name__) app = Flask(__name__)
app.debug = settings.get('debug', False) app.debug = debug
app.config['bigchain_pool'] = util.pool(Bigchain, size=settings.get('threads', 4)) app.config['bigchain_pool'] = util.pool(Bigchain, size=threads)
app.config['monitor'] = Monitor() app.config['monitor'] = Monitor()
app.register_blueprint(info_views, url_prefix='/') app.register_blueprint(info_views, url_prefix='/')
@ -88,6 +91,7 @@ def create_server(settings):
if not settings.get('threads'): if not settings.get('threads'):
settings['threads'] = (multiprocessing.cpu_count() * 2) + 1 settings['threads'] = (multiprocessing.cpu_count() * 2) + 1
app = create_app(settings) app = create_app(debug=settings.get('debug', False),
threads=settings['threads'])
standalone = StandaloneApplication(app, settings) standalone = StandaloneApplication(app, settings)
return standalone return standalone

View File

@ -25,7 +25,7 @@ def app(request, node_config):
restore_config(request, node_config) restore_config(request, node_config)
from bigchaindb.web import server from bigchaindb.web import server
app = server.create_app({'debug': True}) app = server.create_app(debug=True)
return app return app