close sqlalchemy session after a worker's work. closes #4
that was far easier than i anticipated...
This commit is contained in:
parent
3dea73b0bd
commit
5a02d75f7c
12
tasks.py
12
tasks.py
|
@ -1,4 +1,4 @@
|
||||||
from celery import Celery
|
from celery import Celery, Task
|
||||||
|
|
||||||
from app import app as flaskapp
|
from app import app as flaskapp
|
||||||
from app import db
|
from app import db
|
||||||
|
@ -31,6 +31,16 @@ if 'SENTRY_DSN' in flaskapp.config:
|
||||||
register_logger_signal(sentry)
|
register_logger_signal(sentry)
|
||||||
register_signal(sentry)
|
register_signal(sentry)
|
||||||
|
|
||||||
|
|
||||||
|
class DBTask(Task):
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
super().__call__(*args, **kwargs)
|
||||||
|
finally:
|
||||||
|
db.session.close()
|
||||||
|
|
||||||
|
app.Task = DBTask
|
||||||
|
|
||||||
@app.task(autoretry_for=(TwitterError, URLError))
|
@app.task(autoretry_for=(TwitterError, URLError))
|
||||||
def fetch_acc(id, cursor=None):
|
def fetch_acc(id, cursor=None):
|
||||||
acc = Account.query.get(id)
|
acc = Account.query.get(id)
|
||||||
|
|
Loading…
Reference in New Issue