fix: db auto reconnect
This commit is contained in:
parent
94363bc1ae
commit
2e3ce28468
@ -3,7 +3,7 @@ import os
|
|||||||
|
|
||||||
class CMLAccountManager():
|
class CMLAccountManager():
|
||||||
def __init__(self, db_username, db_password) -> None:
|
def __init__(self, db_username, db_password) -> None:
|
||||||
config = {
|
self.config = {
|
||||||
'user': db_username,
|
'user': db_username,
|
||||||
'password': db_password,
|
'password': db_password,
|
||||||
'host': 'cml4.csie.ntu.edu.tw', # 默認是 'localhost'
|
'host': 'cml4.csie.ntu.edu.tw', # 默認是 'localhost'
|
||||||
@ -12,11 +12,20 @@ class CMLAccountManager():
|
|||||||
'ssl_disabled': True
|
'ssl_disabled': True
|
||||||
}
|
}
|
||||||
|
|
||||||
self.conn = mysql.connector.connect(**config)
|
self.conn = mysql.connector.connect(**self.config)
|
||||||
print("Connection successful")
|
print("Connection successful")
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
def find_user(self, username):
|
def find_user(self, username):
|
||||||
|
try:
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
|
except:
|
||||||
|
if self.conn.is_connected():
|
||||||
|
self.conn.close()
|
||||||
|
print("Restart DB Connection")
|
||||||
|
self.conn = mysql.connector.connect(**self.config)
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
query = "SELECT * FROM `People` WHERE `account`=%s"
|
query = "SELECT * FROM `People` WHERE `account`=%s"
|
||||||
param = (username, )
|
param = (username, )
|
||||||
|
|
||||||
|
|||||||
@ -22,8 +22,8 @@ Hi {},
|
|||||||
BIND_SUCCESS = '''
|
BIND_SUCCESS = '''
|
||||||
Hi {},
|
Hi {},
|
||||||
|
|
||||||
我們從資料庫找到您屬於 `{} group`, 我們已經幫您分配到 Discord `{}` 的身份!
|
我們從資料庫找到您屬於 `{} group`, 因此會幫您分配到 Discord `{}` 的身份!
|
||||||
並且已經綁定您的 CMLab 使用者帳號 `{}`,未來若有實驗室相關通知我們能夠快速找到您!
|
同時我們也已經綁定您的 CMLab 使用者帳號 `{}`,未來我們能夠透過自動化工具提供給您相關通知!
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user