Skip to content

Commit 2b1c935

Browse files
authored
Merge branch 'connection-callback' of 'https://github.com/jjmerchante/grimoirelab-core'
Merges #42 Closes #42 Fixes chaoss/grimoirelab#751
2 parents 5323462 + 9eae619 commit 2b1c935

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/grimoirelab/core/scheduler/scheduler.py

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import typing
2424
import uuid
2525

26+
import django.db
2627
import django_rq
2728
import rq.exceptions
2829
import rq.job
@@ -301,6 +302,10 @@ def _on_success_callback(
301302
The new arguments for the job are obtained from the result
302303
of the job object.
303304
"""
305+
# After long-running tasks, the connection may be closed.
306+
# Close unusable connections and let Django reopen them if needed.
307+
django.db.close_old_connections()
308+
304309
try:
305310
job_db = find_job(job.id)
306311
except NotFoundError:
@@ -342,6 +347,10 @@ def _on_failure_callback(
342347
The new arguments for the job are obtained from the result
343348
of the job object.
344349
"""
350+
# After long-running tasks, the connection may be closed.
351+
# Close unusable connections and let Django reopen them if needed.
352+
django.db.close_old_connections()
353+
345354
try:
346355
job_db = find_job(job.id)
347356
except NotFoundError:

0 commit comments

Comments
 (0)