Skip to content

Commit f2ad084

Browse files
committed
Fix for #359 MySQL-OperationalError
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 da0b98c commit f2ad084

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
@@ -181,6 +181,8 @@ def schedule_changed(self):
181181

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

0 commit comments

Comments
 (0)