Created
April 24, 2020 17:57
-
-
Save aoirint/2410aa075f23586b0a381a023705d61a to your computer and use it in GitHub Desktop.
Keep alive MySQL-Django DB Conneciton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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