Skip to content

Fix #359 close database connections after error #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions djcelery/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from celery.utils.timeutils import is_naive

from django.db import transaction
try:
from django.db import close_old_connections
except ImportError:
from django.db import close_connection as close_old_connections
from django.core.exceptions import ObjectDoesNotExist

from .db import commit_on_success
Expand Down Expand Up @@ -182,6 +186,7 @@ def schedule_changed(self):
last, ts = self._last_timestamp, self.Changes.last_change()
except DATABASE_ERRORS as exc:
error('Database gave error: %r', exc, exc_info=1)
close_old_connections()
return False
try:
if ts and ts > (last if last else ts):
Expand Down Expand Up @@ -213,6 +218,7 @@ def sync(self):
# retry later
self._dirty |= _tried
error('Database error while sync: %r', exc, exc_info=1)
close_old_connections()

def update_from_dict(self, dict_):
s = {}
Expand Down