From b90ee832a7ffceac0b0798a12aa3334d1369477b Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Fri, 5 Jan 2018 05:53:40 +0000 Subject: [PATCH] Moved the SQL Alchemy config from staging to all environments During database upgrades and database fail overs there has been errors because the database connection stays open, when a query is run the query fails and the connection is re-established. To avoid these errors shorter timeouts have been used to keep the connections from getting stale. - SQLALCHEMY_POOL_TIMEOUT timeout idle connections after 30 secs - Updated SQLALCHEMY_POOL_RECYCLE to recycle the connection every 5 mins See guide on optimistic disconnect handling - using the pool recycle as a way to manage this: http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-optimistic --- app/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config.py b/app/config.py index ba24b4a5a..9c6a11055 100644 --- a/app/config.py +++ b/app/config.py @@ -121,6 +121,8 @@ class Config(object): SQLALCHEMY_COMMIT_ON_TEARDOWN = False SQLALCHEMY_RECORD_QUERIES = True SQLALCHEMY_TRACK_MODIFICATIONS = True + SQLALCHEMY_POOL_TIMEOUT = 30 + SQLALCHEMY_POOL_RECYCLE = 300 PAGE_SIZE = 50 API_PAGE_SIZE = 250 SMS_CHAR_COUNT_LIMIT = 495 @@ -418,8 +420,6 @@ class Staging(Config): API_RATE_LIMIT_ENABLED = True CHECK_PROXY_HEADER = True REDIS_ENABLED = True - SQLALCHEMY_POOL_TIMEOUT = 30 - SQLALCHEMY_POOL_RECYCLE = 300 API_KEY_LIMITS = { KEY_TYPE_TEAM: {