Ping MySQL supports connection in Django

I have a group of workers who are waiting for tasks (using Django as an ORM). My problem is that if there are no jobs for a given period of time (regardless of the MySQL variable wait_timeout), the MySQL connection time ends, and therefore the worker dies.

My first approach to solving this problem was to simply increase the wait_timeout value to a higher integer, but I thought the best solution would be to ping MySQL every 30 minutes or so if there was no problem keeping the connection alive.

So my question is; how can i use django orm just ping mysql to keep in touch live? What is the best practice here, just do a simple silly request?

+4
source share
4 answers

Django actually handles the database connection (and reconnecting expired) automatically.

The problem was that I process the database transactions manually with one of my employees ( https://docs.djangoproject.com/en/1.3/topics/db/transactions/#django.db.transaction.commit_manually ), and, apparently this forces you to handle the entire database connection yourself.

0
source

Set up a connection pool or manually connect a worker as suggested by @ProblemFactory

http://dev.mysql.com/doc/refman/5.6/en/connector-python-connection-pooling.html

+2
source
from django.db import connection

connection.connection.ping()
+1

- ur, ! , , 30 .

while true:
   sleep(X)
   if some_task:
      connect_to_DB()
      do_something()
0
source

All Articles