Skip to content

Commit

Permalink
Merge pull request #2724 from PnX-SI/fix/worker-session-leak
Browse files Browse the repository at this point in the history
db.session.remove() in celery post run hook
  • Loading branch information
camillemonchicourt authored Sep 28, 2023
2 parents 8cec8a9 + 3dfb7fe commit 4342b29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/geonature/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __call__(self, *args, **kwargs):

app.Task = ContextTask

app.conf.imports += ("geonature.tasks",)
app.conf.imports += tuple(
[ep.module for dist in iter_modules_dist() for ep in dist.entry_points.select(name="tasks")]
)
9 changes: 9 additions & 0 deletions backend/geonature/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from celery.signals import task_postrun

from geonature.utils.env import db
from geonature.utils.celery import celery_app


@task_postrun.connect
def close_session(*args, **kwargs):
db.session.remove()

0 comments on commit 4342b29

Please sign in to comment.