Skip to content

Commit 00db9b7

Browse files
trunnemlauvipy
authored andcommitted
Fix for #359 MySQL-OperationalError (#370)
When the database connection dies (database server crash), the database scheduler of djcelery doesn't close the broken connection for its scheduler update calls. Every 5 seconds an OperationalError: (2006, 'MySQL server has gone away') occurs. This patches checks the database connection when a DATABASE_ERROR occurs and closes the connection when necessary. The database scheduler reconnects automatically on the next try.
1 parent 71a2996 commit 00db9b7

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

djcelery/schedulers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ def schedule_changed(self):
182182

183183
last, ts = self._last_timestamp, self.Changes.last_change()
184184
except DATABASE_ERRORS as exc:
185+
# Close the connection when it is broken
186+
transaction.get_connection().close_if_unusable_or_obsolete()
185187
error('Database gave error: %r', exc, exc_info=1)
186188
return False
187189
try:

0 commit comments

Comments
 (0)