Change registry code to disconnect from the DB before long I/O operations

This commit is contained in:
Joseph Schorr 2014-11-06 18:00:52 -05:00
parent 23d9bd2b42
commit d5bbb57481
3 changed files with 26 additions and 7 deletions

View file

@ -35,6 +35,22 @@ class CallableProxy(Proxy):
raise AttributeError('Cannot use uninitialized Proxy.')
return self.obj(*args, **kwargs)
class CloseForLongOperation(object):
""" Helper object which disconnects the database then reconnects after the nested operation
completes.
"""
def __init__(self, config_object):
self.config_object = config_object
def __enter__(self):
close_db_filter(None)
def __exit__(self, type, value, traceback):
configure(self.config_object)
class UseThenDisconnect(object):
""" Helper object for conducting work with a database and then tearing it down. """
@ -69,6 +85,7 @@ def _db_from_url(url, db_kwargs):
def configure(config_object):
logger.debug('Configuring database')
db_kwargs = dict(config_object['DB_CONNECTION_ARGS'])
write_db_uri = config_object['DB_URI']
db.initialize(_db_from_url(write_db_uri, db_kwargs))