Clean up how we configure DB sessions on app startup
not real sure if the old logic was a "problem" per se, but this cleanup seems warranted and (fingers crossed) shouldn't break anything
This commit is contained in:
parent
c56eadc49b
commit
36f786f0eb
|
@ -31,10 +31,8 @@ import warnings
|
|||
|
||||
import sqlalchemy as sa
|
||||
|
||||
import rattail.db
|
||||
from rattail.config import make_config
|
||||
from rattail.exceptions import ConfigurationError
|
||||
from rattail.db.config import get_engines
|
||||
from rattail.db.types import GPCType
|
||||
|
||||
from pyramid.config import Configurator
|
||||
|
@ -63,27 +61,10 @@ def make_rattail_config(settings):
|
|||
settings['rattail_config'] = rattail_config
|
||||
rattail_config.configure_logging()
|
||||
|
||||
rattail_engines = settings.get('rattail_engines')
|
||||
if not rattail_engines:
|
||||
|
||||
# Load all Rattail database engines from config, and store in settings
|
||||
# dict. This is necessary e.g. in the case of a host server, to have
|
||||
# access to its subordinate store servers.
|
||||
rattail_engines = get_engines(rattail_config)
|
||||
settings['rattail_engines'] = rattail_engines
|
||||
|
||||
# Configure the database session classes. Note that most of the time we'll
|
||||
# be using the Tailbone Session, but occasionally (e.g. within batch
|
||||
# processing threads) we want the Rattail Session. The reason is that
|
||||
# during normal request processing, the Tailbone Session is preferable as
|
||||
# it includes Zope Transaction magic. Within an explicitly-spawned thread
|
||||
# however, this is *not* desirable.
|
||||
rattail.db.Session.configure(bind=rattail_engines['default'])
|
||||
tailbone.db.Session.configure(bind=rattail_engines['default'])
|
||||
if hasattr(rattail_config, 'tempmon_engine'):
|
||||
tailbone.db.TempmonSession.configure(bind=rattail_config.tempmon_engine)
|
||||
if hasattr(rattail_config, 'trainwreck_engine'):
|
||||
tailbone.db.TrainwreckSession.configure(bind=rattail_config.trainwreck_engine)
|
||||
# configure database sessions
|
||||
tailbone.db.Session.configure(bind=rattail_config.rattail_engine)
|
||||
tailbone.db.TempmonSession.configure(bind=rattail_config.tempmon_engine)
|
||||
tailbone.db.TrainwreckSession.configure(bind=rattail_config.trainwreck_engine)
|
||||
|
||||
# Make sure rattail config object uses our scoped session, to avoid
|
||||
# unnecessary connections (and pooling limits).
|
||||
|
|
Loading…
Reference in a new issue