This commit is contained in:
wuaho 2021-08-14 11:19:50 +08:00
parent eef92b3fdc
commit 86aa16574e

View File

@ -11,13 +11,14 @@ __all__ = 'Transmitter',
class Ping(threading.Thread): class Ping(threading.Thread):
def __init__(self, db_client, log): def __init__(self, db_client, p, log):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.daemon = True self.daemon = True
self.ping_ts = 0 self.ping_ts = 0
self.time_out = 60 self.time_out = 60
self.log = log self.log = log
self.db_client = db_client self.db_client = db_client
self.p = p
def run(self): def run(self):
while True: while True:
@ -26,7 +27,7 @@ class Ping(threading.Thread):
# 保持连接 # 保持连接
try: try:
self.ping_ts = ts self.ping_ts = ts
self.log.info('保持连接 ping') self.log.info(f'保持连接{self.p} ping')
self.db_client.execute('select 1') self.db_client.execute('select 1')
except: except:
self.log.error('ping error') self.log.error('ping error')
@ -44,7 +45,7 @@ class Transmitter:
self.p = p self.p = p
def start_ping(self): def start_ping(self):
t = Ping(self.db_client, self.log) t = Ping(self.db_client, self.p, self.log)
t.start() t.start()
def add_source(self, handler, bulk_max=1000, time_out=60): def add_source(self, handler, bulk_max=1000, time_out=60):