Change verbs to use short lived database connections

This commit is contained in:
Joseph Schorr 2014-11-06 17:50:48 -05:00
parent c569299e5c
commit 23d9bd2b42
3 changed files with 37 additions and 16 deletions

View file

@ -35,6 +35,19 @@ class CallableProxy(Proxy):
raise AttributeError('Cannot use uninitialized Proxy.')
return self.obj(*args, **kwargs)
class UseThenDisconnect(object):
""" Helper object for conducting work with a database and then tearing it down. """
def __init__(self, config_object):
self.config_object = config_object
def __enter__(self):
configure(self.config_object)
def __exit__(self, type, value, traceback):
close_db_filter(None)
db = Proxy()
read_slave = Proxy()
db_random_func = CallableProxy()