Reconnect to Gerrit database if needed
* jeepyb/gerritdb.py(connect): If the database connection is being reused for a connect call, issue a ping and pass the reconnect option so that a reconnection attempt will be made in the event the socket has timed out or otherwise disconnected. Note that this only works for the MySQLdb driver, so a different solution will likely be needed for psycopg2. Alternatively, switching to an ORM like sqlalchemy would get us this for free, but is a more involved change. Change-Id: I591d40998e208f18ac5c43bafd7bccb98be6a9c8 Closes-Story: #2000017
This commit is contained in:
parent
f13b71bfe8
commit
59c6b84c02
|
@ -60,4 +60,11 @@ def connect():
|
|||
import psycopg2
|
||||
db_connection = psycopg2.connect(
|
||||
host=DB_HOST, user=DB_USER, password=DB_PASS, database=DB_DB)
|
||||
else:
|
||||
try:
|
||||
# Make sure the database is responding and reconnect if not
|
||||
db_connection.ping(True)
|
||||
except AttributeError:
|
||||
# This database driver lacks a ping implementation
|
||||
pass
|
||||
return db_connection
|
||||
|
|
Loading…
Reference in New Issue