MT#58395 reconnect when pymysql connection is closed

* ping existing pymysql connection and automatically reconnect
  if it was closed

Change-Id: Ie1bd230cd5a28201f6a6809f33c392b821c17ef0
mr12.2
Kirill Solomko 1 year ago
parent 84e2286776
commit dfb3a8b7f9

@ -922,6 +922,7 @@ def apply_up_script(script_name: str, revision: int) -> int:
config._temp_sql_file.write(file.read()) config._temp_sql_file.write(file.read())
try: try:
config.db_conn.ping(reconnect=True)
if not config.batch_mode: if not config.batch_mode:
with config.db_conn.cursor() as cursor: with config.db_conn.cursor() as cursor:
cursor.execute(f""" cursor.execute(f"""
@ -1023,6 +1024,7 @@ def apply_down_script(script_name: str, revision: int) -> int:
config._temp_sql_file.write(file.read()) config._temp_sql_file.write(file.read())
try: try:
config.db_conn.ping(reconnect=True)
if not config.batch_mode: if not config.batch_mode:
with config.db_conn.cursor() as cursor: with config.db_conn.cursor() as cursor:
rows = 0 rows = 0
@ -1173,12 +1175,12 @@ def check_active_node() -> None:
if active: if active:
if not config.force: if not config.force:
log(c_str(f""" log(c_str(f"""
Stopping because the current node {config.node_name} is active. stopping because the current node {config.node_name} is active.
""")) """))
shutdown(1) shutdown(1)
else: else:
debug(c_str( debug(c_str(
f"""current node {config.node_name} is inactive f"""current node {config.node_name} is active
but force mode is enabled.""" but force mode is enabled."""
)) ))

Loading…
Cancel
Save