Skip to content

Instantly share code, notes, and snippets.

@aoirint
Created April 24, 2020 17:57
Show Gist options
  • Save aoirint/2410aa075f23586b0a381a023705d61a to your computer and use it in GitHub Desktop.
Save aoirint/2410aa075f23586b0a381a023705d61a to your computer and use it in GitHub Desktop.
Keep alive MySQL-Django DB Conneciton
from django.db import connection
import schedule
def do_keep_alive():
print('Sending keep alive query to DB.')
with connection.cursor() as cur:
cur.execute('SELECT 0') # dummy query to keep mysql connection alive
schedule.every(30).minutes.do(do_keep_alive)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment