Fix db reconnect issue under django 1.6+

Django's orm layer will not auto-reconnect after it looses
the connection to the mysql server, until you manually close the
database connection in django 1.6 and above.

(see: https://code.djangoproject.com/ticket/21597)

This is an issue for persistant connections, as MySQL will timeout
inactive connections, and any loss of the db connection will cause
the stacktach worker to simply repeat the error
"MySQL server has gone away" until restarted.

This fix will allow the stacktach worker to properly reconnect.

Change-Id: I0b0bc75b7e21fd183f3b0e7a55d727ff98d6f02b
This commit is contained in:
Monsyne Dragon 2014-07-24 00:47:35 +00:00
parent bea3a75a35
commit 3e4eb35653

View File

@ -35,6 +35,7 @@ except ImportError:
from pympler.process import ProcessMemoryInfo
from django.db import connection as db_connection
from stacktach import db
from stacktach import message_service
from stacktach import stacklog
@ -171,6 +172,8 @@ def continue_running():
def exit_or_sleep(exit=False):
if exit:
sys.exit(1)
#so django 1.6+ will properly reconnect
db_connection.close()
time.sleep(5)