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
85f1e699
Unverified
Commit
85f1e699
authored
Mar 05, 2018
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: push to s3
parent
c46d418e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
recorder.py
coco/recorder.py
+35
-9
No files found.
coco/recorder.py
View file @
85f1e699
...
...
@@ -132,7 +132,7 @@ class ServerReplayRecorder(ReplayRecorder):
self
.
push_to_server
(
session_id
)
def
push_to_server
(
self
,
session_id
):
if
self
.
push_to_s3
(
3
,
session_id
):
if
self
.
upload_replay
(
3
,
session_id
):
if
self
.
finish_replay
(
3
,
session_id
):
return
True
else
:
...
...
@@ -140,15 +140,18 @@ class ServerReplayRecorder(ReplayRecorder):
else
:
return
False
def
push_to_s3
(
self
,
times
,
session_id
):
def
push_local
(
self
,
session_id
):
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
session_id
)
def
upload_replay
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
session_id
):
if
self
.
push_local
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log "
,
session_id
)
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log, try {} times"
,
session_id
,
times
)
return
self
.
push_to_s3
(
times
-
1
,
session_id
)
return
self
.
upload_replay
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log"
,
session_id
)
return
False
...
...
@@ -285,7 +288,7 @@ class S3ReplayRecorder(ServerReplayRecorder):
else
:
self
.
s3
=
boto3
.
client
(
's3'
)
def
push_to_s
erver
(
self
,
session_id
):
def
push_to_s
3
(
self
,
session_id
):
logger
.
debug
(
"push to server"
)
try
:
self
.
s3
.
upload_file
(
...
...
@@ -293,10 +296,33 @@ class S3ReplayRecorder(ServerReplayRecorder):
self
.
bucket
,
self
.
app
.
config
.
get
(
"NAME"
,
"coco"
)
+
time
.
strftime
(
'
%
Y-
%
m-
%
d'
,
time
.
localtime
(
self
.
starttime
))
+
'/'
+
session_id
+
'.replay.gz'
)
return
True
except
:
return
self
.
app
.
service
.
push_session_replay
(
os
.
path
.
join
(
self
.
app
.
config
[
'LOG_DIR'
],
session_id
+
'.replay.gz'
),
session_id
)
return
False
def
upload_replay
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
push_to_s3
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log to S3 "
,
session_id
)
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log to S3, try {} times"
,
session_id
,
times
)
return
self
.
upload_replay
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log S3, try to push to local"
,
session_id
)
return
self
.
upload_replay_to_local
(
3
,
session_id
)
def
upload_replay_to_local
(
self
,
times
,
session_id
):
if
times
>
0
:
if
self
.
push_local
(
session_id
):
logger
.
info
(
"success push session: {}'s replay log "
,
session_id
)
return
True
else
:
logger
.
error
(
"failed report session {}'s replay log, try {} times"
,
session_id
,
times
)
return
self
.
upload_replay_to_local
(
times
-
1
,
session_id
)
else
:
logger
.
error
(
"failed report session {}'s replay log"
,
session_id
)
return
False
def
get_command_recorder_class
(
config
):
...
...
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