How to handle database disconnects while using mysql jobstore with Flask Sqlalchemy

795 Views Asked by At

I am using Flask Sqlalchemy and have given mysql as job store while initiating the Scheduler. But Sometimes when I add job to scheduler it throws 'Mysql Server has gone away' error probably client has disconnected..Can anyone suggest if we can handle this using some event listeners and reconnect to the database..

1

There are 1 best solutions below

3
On

MySQL closes it self the stale connections (8 hours of inactivity by default). You can set the pool recycle to solve this problem.

app.config["SQLALCHEMY_POOL_RECYCLE"] = 300

more info.