From e8abbd57bb7f2f1a028632feed2edacae9e0b1cc Mon Sep 17 00:00:00 2001 From: Jalin Date: Sat, 19 Jan 2019 15:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20cdn=20=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.docker.py.example | 1 + env.py.example | 1 + py12306/config.py | 1 + py12306/helpers/cdn.py | 9 +++++++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/env.docker.py.example b/env.docker.py.example index 8a662fb..2e2de55 100644 --- a/env.docker.py.example +++ b/env.docker.py.example @@ -104,6 +104,7 @@ WEB_PORT = 8008 # 监听端口 # 是否开启 CDN 查询 CDN_ENABLED = 0 +CDN_CHECK_TIME_OUT = 1 # 检测单个 cdn 是否可用超时时间 # 查询任务 QUERY_JOBS = [ diff --git a/env.py.example b/env.py.example index 1a0163b..a3e4690 100644 --- a/env.py.example +++ b/env.py.example @@ -102,6 +102,7 @@ WEB_PORT = 8008 # 监听端口 # 是否开启 CDN 查询 CDN_ENABLED = 0 +CDN_CHECK_TIME_OUT = 1 # 检测单个 cdn 是否可用超时时间 # 查询任务 QUERY_JOBS = [ diff --git a/py12306/config.py b/py12306/config.py index 74fcae5..0e69ef3 100644 --- a/py12306/config.py +++ b/py12306/config.py @@ -86,6 +86,7 @@ class Config: # CDN CDN_ENABLED = 0 + CDN_CHECK_TIME_OUT = 2 CDN_ITEM_FILE = PROJECT_DIR + 'data/cdn.txt' CDN_ENABLED_AVAILABLE_ITEM_FILE = QUERY_DATA_DIR + 'available.json' diff --git a/py12306/helpers/cdn.py b/py12306/helpers/cdn.py index 958121e..37a97dd 100644 --- a/py12306/helpers/cdn.py +++ b/py12306/helpers/cdn.py @@ -31,7 +31,7 @@ class Cdn: safe_stay_time = 0.2 retry_num = 1 - thread_num = 8 + thread_num = 5 check_time_out = 3 last_check_at = 0 @@ -40,6 +40,7 @@ class Cdn: def __init__(self): self.cluster = Cluster() + self.init_config() create_thread_and_run(self, 'watch_cdn', False) def init_data(self): @@ -50,8 +51,12 @@ class Cdn: self.is_ready = False self.is_recheck = False + def init_config(self): + self.check_time_out = Config().CDN_CHECK_TIME_OUT + def update_cdn_status(self, auto=False): if auto: + self.init_config() if Config().is_cdn_enabled(): self.run() else: @@ -100,7 +105,7 @@ class Cdn: if self.last_check_at: self.last_check_at = str_to_time(self.last_check_at) self.available_items = result.get('items', []) self.unavailable_items = result.get('fail_items', []) - CommonLog.add_quick_log(CommonLog.MESSAGE_CDN_RESTORE_SUCCESS.format(self.last_check_at )).flush() + CommonLog.add_quick_log(CommonLog.MESSAGE_CDN_RESTORE_SUCCESS.format(self.last_check_at)).flush() return True return False