Skip to content
Snippets Groups Projects
Commit 5efa6d28 authored by Gunnar Schaefer's avatar Gunnar Schaefer
Browse files

Improve app factory encapsulation

parent f5eec2f5
No related branches found
No related tags found
No related merge requests found
......@@ -121,24 +121,23 @@ def dispatcher(router, request, response):
response.headers['Content-Type'] = 'application/json; charset=utf-8'
application = webapp2.WSGIApplication(routes)
application.router.set_dispatcher(dispatcher)
# configure new relic
# don't use config.get_item() as we don't want to require the database at startup
if config.__config['core']['newrelic']:
try:
import newrelic.agent, newrelic.api.exceptions
newrelic.agent.initialize(config.__config['core']['newrelic'])
application = newrelic.agent.WSGIApplicationWrapper(application)
log.info('New Relic detected and loaded. Monitoring enabled.')
except ImportError:
log.critical('New Relic libraries not found.')
sys.exit(1)
except newrelic.api.exceptions.ConfigurationError:
log.critical('New Relic detected, but configuration invalid.')
sys.exit(1)
def app_factory(_, **__):
def app_factory(*_, **__):
# don't use config.get_item() as we don't want to require the database at startup
application = webapp2.WSGIApplication(routes, debug=config.__config['core']['debug'])
application.router.set_dispatcher(dispatcher)
# configure new relic
if config.__config['core']['newrelic']:
try:
import newrelic.agent, newrelic.api.exceptions
newrelic.agent.initialize(config.__config['core']['newrelic'])
application = newrelic.agent.WSGIApplicationWrapper(application)
log.info('New Relic detected and loaded. Monitoring enabled.')
except ImportError:
log.critical('New Relic libraries not found.')
sys.exit(1)
except newrelic.api.exceptions.ConfigurationError:
log.critical('New Relic detected, but configuration invalid.')
sys.exit(1)
return application
......@@ -22,6 +22,7 @@ logging.getLogger('paste.httpserver').setLevel(logging.WARNING) # silence Paste
DEFAULT_CONFIG = {
'core': {
'log_level': 'info',
'debug': False,
'insecure': False,
'newrelic': None,
},
......
......@@ -2,7 +2,7 @@
from api import api
application = api.application
application = api.app_factory()
# FIXME: all code below should removed and ported into an app server independent framework
......
......@@ -5,7 +5,8 @@
#SCITRAN_SYSTEM_RUNTIME="./runtime"
#SCITRAN_SYSTEM_SSL_PEM="*"
#SCITRAN_CORE_INSECURE=false
#SCITRAN_CORE_DEBUG=false # emit stack trace on error
#SCITRAN_CORE_INSECURE=false # accept user name as query param
#SCITRAN_CORE_LOG_LEVEL=debug
#SCITRAN_CORE_NEWRELIC=none
......@@ -17,8 +18,8 @@
#SCITRAN_SITE_SSL_CERT=""
#SCITRAN_PERSISTENT_PATH="./persistent"
#SCITRAN_PERSISTENT_DATA_PATH="./persistent/data" # for fine-grain control
#SCITRAN_PERSISTENT_DB_PATH="./persistent/db" # for fine-grain control
#SCITRAN_PERSISTENT_DATA_PATH="./persistent/data" # for fine-grain control
#SCITRAN_PERSISTENT_DB_PATH="./persistent/db" # for fine-grain control
#SCITRAN_PERSISTENT_DB_PORT=9001
#SCITRAN_PERSISTENT_DB_URI="mongodb://localhost:$SCITRAN_PERSISTENT_DB_PORT/scitran"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment