Skip to content

Commit 9001f0f

Browse files
bigmars86auvipy
authored andcommitted
Prevent MySQL has gone away errors (#58)
Prevents Error "MySQL has gone away" when Django tries to go through old, timed-out or closed connections. After calling close_old_connections() Django opens a new connection if the old one was closed.
1 parent 2d96dfa commit 9001f0f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

django_celery_beat/schedulers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from celery.utils.log import get_logger
1414
from kombu.utils.json import dumps, loads
1515

16-
from django.db import transaction
16+
from django.db import transaction, close_old_connections
1717
from django.db.utils import DatabaseError
1818
from django.core.exceptions import ObjectDoesNotExist
1919

@@ -232,6 +232,7 @@ def sync(self):
232232
info('Writing entries...')
233233
_tried = set()
234234
try:
235+
close_old_connections()
235236
with transaction.atomic():
236237
while self._dirty:
237238
try:

0 commit comments

Comments
 (0)