|
@@ -7,6 +7,8 @@
|
|
|
# @contact: renyupeng@c-top.com.cn
|
|
|
import logging
|
|
|
import time
|
|
|
+from sqlite3 import OperationalError
|
|
|
+
|
|
|
import pymysql
|
|
|
from Apietl.constant.ConfConstant import ConfConstant
|
|
|
|
|
@@ -43,8 +45,8 @@ class TidbConn:
|
|
|
|
|
|
@classmethod
|
|
|
def quary(cls, sql):
|
|
|
- TidbConn._reConn(num=28800, stime=3)
|
|
|
mysql_conn = TidbConn.get_connection()
|
|
|
+ TidbConn._reConn(mysql_conn)
|
|
|
cur = mysql_conn.cursor()
|
|
|
cur.execute(sql)
|
|
|
result = cur.fetchall()
|
|
@@ -72,13 +74,24 @@ class TidbConn:
|
|
|
|
|
|
@staticmethod
|
|
|
def upsert(conn, sql_buff):
|
|
|
- TidbConn._reConn(num=28800, stime=3)
|
|
|
+ TidbConn._reConn(conn)
|
|
|
try:
|
|
|
TidbConn.exec_sql(conn, sql_buff)
|
|
|
except Exception as e:
|
|
|
logging.error('失败详细信息:', repr(e))
|
|
|
TidbConn.get_connection().commit()
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def _reCon(cls, conn):
|
|
|
+ """ MySQLdb.OperationalError异常"""
|
|
|
+ # self.con.close()
|
|
|
+ while True:
|
|
|
+ try:
|
|
|
+ conn.ping()
|
|
|
+ break
|
|
|
+ except OperationalError:
|
|
|
+ conn.ping(True)
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
db = TidbConn.get_connection()
|