Disconnect from read slaves when the request ends.

This commit is contained in:
Jake Moshenko 2014-07-07 17:06:53 -04:00
parent 13de458320
commit 9932a8199f

View file

@ -2,11 +2,12 @@ import logging
import logging.config import logging.config
import uuid import uuid
from peewee import Proxy
from app import app as application from app import app as application
from flask import request, Request from flask import request, Request
from util.names import urn_generator from util.names import urn_generator
from data.model import db as model_db, read_slave
from data.model import db as model_db
# Turn off debug logging for boto # Turn off debug logging for boto
logging.getLogger('boto').setLevel(logging.CRITICAL) logging.getLogger('boto').setLevel(logging.CRITICAL)
@ -76,6 +77,10 @@ def close_db(exc):
logger.debug('Disconnecting from database.') logger.debug('Disconnecting from database.')
db.close() db.close()
if read_slave.obj is not None and not read_slave.is_closed():
logger.debug('Disconnecting from read slave.')
read_slave.close()
application.teardown_request(close_db) application.teardown_request(close_db)
application.request_class = RequestWithId application.request_class = RequestWithId