Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
py12306
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
python
py12306
Commits
3a7700c2
Commit
3a7700c2
authored
Jan 19, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加 cdn 检测超时配置
parent
c613b54d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
2 deletions
+10
-2
env.docker.py.example
env.docker.py.example
+1
-0
env.py.example
env.py.example
+1
-0
config.py
py12306/config.py
+1
-0
cdn.py
py12306/helpers/cdn.py
+7
-2
No files found.
env.docker.py.example
View file @
3a7700c2
...
@@ -104,6 +104,7 @@ WEB_PORT = 8008 # 监听端口
...
@@ -104,6 +104,7 @@ WEB_PORT = 8008 # 监听端口
# 是否开启 CDN 查询
# 是否开启 CDN 查询
CDN_ENABLED = 0
CDN_ENABLED = 0
CDN_CHECK_TIME_OUT = 1 # 检测单个 cdn 是否可用超时时间
# 查询任务
# 查询任务
QUERY_JOBS = [
QUERY_JOBS = [
...
...
env.py.example
View file @
3a7700c2
...
@@ -102,6 +102,7 @@ WEB_PORT = 8008 # 监听端口
...
@@ -102,6 +102,7 @@ WEB_PORT = 8008 # 监听端口
# 是否开启 CDN 查询
# 是否开启 CDN 查询
CDN_ENABLED = 0
CDN_ENABLED = 0
CDN_CHECK_TIME_OUT = 1 # 检测单个 cdn 是否可用超时时间
# 查询任务
# 查询任务
QUERY_JOBS = [
QUERY_JOBS = [
...
...
py12306/config.py
View file @
3a7700c2
...
@@ -86,6 +86,7 @@ class Config:
...
@@ -86,6 +86,7 @@ class Config:
# CDN
# CDN
CDN_ENABLED
=
0
CDN_ENABLED
=
0
CDN_CHECK_TIME_OUT
=
2
CDN_ITEM_FILE
=
PROJECT_DIR
+
'data/cdn.txt'
CDN_ITEM_FILE
=
PROJECT_DIR
+
'data/cdn.txt'
CDN_ENABLED_AVAILABLE_ITEM_FILE
=
QUERY_DATA_DIR
+
'available.json'
CDN_ENABLED_AVAILABLE_ITEM_FILE
=
QUERY_DATA_DIR
+
'available.json'
...
...
py12306/helpers/cdn.py
View file @
3a7700c2
...
@@ -31,7 +31,7 @@ class Cdn:
...
@@ -31,7 +31,7 @@ class Cdn:
safe_stay_time
=
0.2
safe_stay_time
=
0.2
retry_num
=
1
retry_num
=
1
thread_num
=
8
thread_num
=
5
check_time_out
=
3
check_time_out
=
3
last_check_at
=
0
last_check_at
=
0
...
@@ -40,6 +40,7 @@ class Cdn:
...
@@ -40,6 +40,7 @@ class Cdn:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
cluster
=
Cluster
()
self
.
cluster
=
Cluster
()
self
.
init_config
()
create_thread_and_run
(
self
,
'watch_cdn'
,
False
)
create_thread_and_run
(
self
,
'watch_cdn'
,
False
)
def
init_data
(
self
):
def
init_data
(
self
):
...
@@ -50,8 +51,12 @@ class Cdn:
...
@@ -50,8 +51,12 @@ class Cdn:
self
.
is_ready
=
False
self
.
is_ready
=
False
self
.
is_recheck
=
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
):
def
update_cdn_status
(
self
,
auto
=
False
):
if
auto
:
if
auto
:
self
.
init_config
()
if
Config
()
.
is_cdn_enabled
():
if
Config
()
.
is_cdn_enabled
():
self
.
run
()
self
.
run
()
else
:
else
:
...
@@ -100,7 +105,7 @@ class Cdn:
...
@@ -100,7 +105,7 @@ class Cdn:
if
self
.
last_check_at
:
self
.
last_check_at
=
str_to_time
(
self
.
last_check_at
)
if
self
.
last_check_at
:
self
.
last_check_at
=
str_to_time
(
self
.
last_check_at
)
self
.
available_items
=
result
.
get
(
'items'
,
[])
self
.
available_items
=
result
.
get
(
'items'
,
[])
self
.
unavailable_items
=
result
.
get
(
'fail_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
True
return
False
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment