Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
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
ops
coco
Commits
938dd0f9
Unverified
Commit
938dd0f9
authored
Feb 20, 2019
by
老广
Committed by
GitHub
Feb 20, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #183 from jumpserver/dev
[Update] 拆分大的函数func
parents
849c2ba9
0508afc4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
17 deletions
+27
-17
app.py
coco/app.py
+27
-17
No files found.
coco/app.py
View file @
938dd0f9
...
@@ -138,37 +138,47 @@ class Coco:
...
@@ -138,37 +138,47 @@ class Coco:
max_try
=
5
max_try
=
5
upload_failed
=
defaultdict
(
int
)
upload_failed
=
defaultdict
(
int
)
def
retry_upload_replay
(
session_id
,
full_path
,
target
):
recorder
=
get_replay_recorder
()
recorder
.
file_path
=
full_path
recorder
.
session_id
=
session_id
recorder
.
target
=
target
ok
,
msg
=
recorder
.
upload_replay
()
if
ok
:
upload_failed
.
pop
(
session_id
,
None
)
else
:
upload_failed
[
session_id
]
+=
1
def
check_replay_need_upload
(
full_path
):
filename
=
os
.
path
.
basename
(
full_path
)
suffix
=
filename
.
split
(
'.'
)[
-
1
]
if
suffix
!=
'gz'
:
return
False
session_id
=
filename
.
split
(
'.'
)[
0
]
if
len
(
session_id
)
!=
36
:
return
False
stat
=
os
.
stat
(
full_path
)
if
stat
.
st_mtime
>
time
.
time
()
-
24
*
60
*
60
:
return
False
def
func
():
def
func
():
while
not
self
.
stop_evt
.
is_set
():
while
not
self
.
stop_evt
.
is_set
():
for
d
in
os
.
listdir
(
replay_dir
):
for
d
in
os
.
listdir
(
replay_dir
):
date_path
=
os
.
path
.
join
(
replay_dir
,
d
)
date_path
=
os
.
path
.
join
(
replay_dir
,
d
)
for
filename
in
os
.
listdir
(
date_path
):
for
filename
in
os
.
listdir
(
date_path
):
suffix
=
filename
.
split
(
'.'
)[
-
1
]
full_path
=
os
.
path
.
join
(
date_path
,
filename
)
if
suffix
!=
'gz'
:
continue
session_id
=
filename
.
split
(
'.'
)[
0
]
session_id
=
filename
.
split
(
'.'
)[
0
]
if
len
(
session_id
)
!=
36
:
continue
full_path
=
os
.
path
.
join
(
date_path
,
filename
)
stat
=
os
.
stat
(
full_path
)
# 是否是一天前的,因为现在多个coco共享了日志目录,
# 是否是一天前的,因为现在多个coco共享了日志目录,
# 不能单纯判断session是否关闭
# 不能单纯判断session是否关闭
if
stat
.
st_mtime
>
time
.
time
()
-
24
*
60
*
60
:
if
not
check_replay_need_upload
(
full_path
)
:
continue
continue
# 失败次数过多
# 失败次数过多
if
session_id
in
upload_failed
\
if
session_id
in
upload_failed
\
and
upload_failed
[
session_id
]
>=
max_try
:
and
upload_failed
[
session_id
]
>=
max_try
:
continue
continue
recorder
=
get_replay_recorder
()
target
=
os
.
path
.
join
(
d
,
filename
)
recorder
.
file_path
=
full_path
retry_upload_replay
(
session_id
,
full_path
,
target
)
recorder
.
session_id
=
session_id
recorder
.
target
=
os
.
path
.
join
(
d
,
filename
)
ok
,
msg
=
recorder
.
upload_replay
()
if
ok
:
upload_failed
.
pop
(
session_id
,
None
)
else
:
upload_failed
[
session_id
]
+=
1
time
.
sleep
(
1
)
time
.
sleep
(
1
)
time
.
sleep
(
interval
)
time
.
sleep
(
interval
)
thread
=
threading
.
Thread
(
target
=
func
)
thread
=
threading
.
Thread
(
target
=
func
)
...
...
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