WSGI: Use current_app if it's available, otherwise make it available

ARA leverages the Flask application context heavily to share data and
configuration between requests and components.

The WSGI script always created new application contexts and didn't
re-use the current application context if it existed in memory.

Change-Id: Ice93125fd4711cb0d22233c99eb354a0d688092e
This commit is contained in:
David Moreau Simard 2018-04-08 16:03:02 -04:00
parent 259d3bed08
commit fa624de6f7
No known key found for this signature in database
GPG Key ID: 33A07694CBB71ECC
1 changed files with 10 additions and 3 deletions

View File

@ -21,7 +21,11 @@
import os
import logging
from ara.webapp import create_app
from flask import current_app
log = logging.getLogger(__name__)
app = create_app()
def application(environ, start_response):
@ -31,9 +35,12 @@ def application(environ, start_response):
if 'ANSIBLE_CONFIG' not in os.environ:
log.warn('ANSIBLE_CONFIG environment variable not found.')
from ara.webapp import create_app
app = create_app()
return app(environ, start_response)
if not current_app:
ctx = app.app_context()
ctx.push()
return app(environ, start_response)
else:
return current_app(environ, start_response)
def main():