Unify the database connection lifecycle across all workers
This commit is contained in:
parent
38cb63d195
commit
2f626f2691
7 changed files with 111 additions and 130 deletions
|
@ -6,12 +6,10 @@ import socket
|
|||
from threading import Event
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from datetime import datetime, timedelta
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
from raven import Client
|
||||
|
||||
from app import app
|
||||
from data.model import db
|
||||
from data.database import UseThenDisconnect
|
||||
from functools import wraps
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -44,7 +42,8 @@ class Worker(object):
|
|||
@wraps(operation_func)
|
||||
def _operation_func():
|
||||
try:
|
||||
return operation_func()
|
||||
with UseThenDisconnect(app.config):
|
||||
return operation_func()
|
||||
except Exception:
|
||||
logger.exception('Operation raised exception')
|
||||
if self._raven_client:
|
||||
|
|
Reference in a new issue