|
@@ -1,253 +0,0 @@
|
|
|
-from hub import methods, Global
|
|
|
-
|
|
|
-import asyncio
|
|
|
-import threading
|
|
|
-import traceback
|
|
|
-
|
|
|
-
|
|
|
-class LineManage(object):
|
|
|
- """"""
|
|
|
-
|
|
|
- line_dict = {}
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def run_forever(cls):
|
|
|
- tasks = [cls.check_loop()]
|
|
|
- _loop = asyncio.new_event_loop()
|
|
|
- asyncio.set_event_loop(_loop)
|
|
|
- loop = asyncio.get_event_loop()
|
|
|
- loop.run_until_complete(asyncio.wait(tasks))
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def run_background(cls, is_back_run=True):
|
|
|
- t1 = threading.Thread(target=cls.run_forever)
|
|
|
- t1.start()
|
|
|
-
|
|
|
- @classmethod
|
|
|
- async def check_loop(cls):
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- while True:
|
|
|
-
|
|
|
- try:
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- now_ts = methods.now_ts()
|
|
|
-
|
|
|
-
|
|
|
- for username in list(cls.line_dict.keys()):
|
|
|
-
|
|
|
- try:
|
|
|
-
|
|
|
-
|
|
|
- _ws, last_live_at, _id = cls.line_dict.get(username)
|
|
|
- methods.debug_log(f"LineManage.check_loop87", f"#username: {username}"
|
|
|
- f" | #last_live_at: {last_live_at}"
|
|
|
- f" | #now_ts: {now_ts}")
|
|
|
-
|
|
|
-
|
|
|
- if now_ts - last_live_at >= 3 * 60:
|
|
|
- cls.line_dict.pop(username)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- except Exception as exception:
|
|
|
-
|
|
|
-
|
|
|
- if not cls.check_line_is_live(username):
|
|
|
- cls.line_dict.pop(username)
|
|
|
-
|
|
|
- if exception.__class__.__name__ == 'RuntimeError':
|
|
|
- methods.debug_log(f"LineManage.check_loop194", f"d2: {cls.get_line_state()}")
|
|
|
- else:
|
|
|
- methods.debug_log("LineManage.check_loop194", f"#e: {exception.__class__.__name__}")
|
|
|
- methods.debug_log("LineManage.check_loop194", f"#t: {traceback.format_exc()}")
|
|
|
-
|
|
|
-
|
|
|
- methods.debug_log(f"LineManage.check_loop198", f"wait 1 minutes check again")
|
|
|
- await asyncio.sleep(60)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- except Exception as exception:
|
|
|
-
|
|
|
- methods.debug_log(f"LineManage.check_loop208", f"#e: {exception.__class__.__name__}")
|
|
|
- methods.debug_log(f"LineManage.check_loop208", f"#t: {traceback.format_exc()}")
|
|
|
- methods.debug_log(f"LineManage.check_loop208", f"wait 1 minutes try again!")
|
|
|
- await asyncio.sleep(60)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_line_total(cls):
|
|
|
- count = 0
|
|
|
- for k, v in cls.line_dict.items():
|
|
|
- count += 1
|
|
|
- return count
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def check_line_is_live(cls, line_id):
|
|
|
- d1 = {
|
|
|
- 0: 'CONNECTING',
|
|
|
- 1: 'CONNECTED',
|
|
|
- 2: 'DISCONNECTED',
|
|
|
- }
|
|
|
- _ws, _, _ = cls.line_dict.get(line_id)
|
|
|
- if _ws and d1.get(_ws.client_state.value) != 'DISCONNECTED':
|
|
|
- return True
|
|
|
- else:
|
|
|
- return False
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def get_line_state(cls):
|
|
|
- d1 = {
|
|
|
- 0: 'CONNECTING',
|
|
|
- 1: 'CONNECTED',
|
|
|
- 2: 'DISCONNECTED',
|
|
|
- }
|
|
|
- d2 = dict()
|
|
|
- for line_id, line in cls.line_dict.items():
|
|
|
- state = d1.get(line.client_state.value)
|
|
|
- _id = line_id[-6:]
|
|
|
- d2[_id] = state
|
|
|
- return d2
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|