Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
jumpserver
Commits
6ebe8e16
Commit
6ebe8e16
authored
Oct 21, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改读取日志时可能解码失败
parent
86522627
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
encode.py
apps/common/utils/encode.py
+4
-0
ws.py
apps/ops/ws.py
+14
-6
No files found.
apps/common/utils/encode.py
View file @
6ebe8e16
...
...
@@ -182,3 +182,7 @@ def encrypt_password(password, salt=None):
def
get_signer
():
signer
=
Signer
(
settings
.
SECRET_KEY
)
return
signer
def
ensure_last_char_is_ascii
(
data
):
remain
=
''
apps/ops/ws.py
View file @
6ebe8e16
...
...
@@ -3,11 +3,13 @@ import os
import
threading
import
json
from
c
elery.result
import
AsyncResult
from
c
ommon.utils
import
get_logger
from
.celery.utils
import
get_celery_task_log_path
from
channels.generic.websocket
import
JsonWebsocketConsumer
logger
=
get_logger
(
__name__
)
class
CeleryLogWebsocket
(
JsonWebsocketConsumer
):
disconnected
=
False
...
...
@@ -22,6 +24,7 @@ class CeleryLogWebsocket(JsonWebsocketConsumer):
self
.
handle_task
(
task_id
)
def
handle_task
(
self
,
task_id
):
logger
.
info
(
"Task id: {}"
.
format
(
task_id
))
log_path
=
get_celery_task_log_path
(
task_id
)
def
func
():
...
...
@@ -34,19 +37,24 @@ class CeleryLogWebsocket(JsonWebsocketConsumer):
continue
self
.
send_json
({
'message'
:
'
\r\n
'
})
try
:
task_log_f
=
open
(
log_path
)
logger
.
debug
(
'Task log path: {}'
.
format
(
log_path
))
task_log_f
=
open
(
log_path
,
'rb'
)
break
except
OSError
:
return
if
not
task_log_f
:
return
while
not
self
.
disconnected
:
data
=
task_log_f
.
readline
()
if
data
:
data
=
data
.
replace
(
'
\n
'
,
'
\r\n
'
)
self
.
send_json
({
'message'
:
data
,
'task'
:
task_id
})
if
data
.
startswith
(
'Task'
)
and
data
.
find
(
'succeeded'
):
data
=
data
.
replace
(
b
'
\n
'
,
b
'
\r\n
'
)
self
.
send_json
({
'message'
:
data
.
decode
(
errors
=
'ignore'
)
,
'task'
:
task_id
})
if
data
.
startswith
(
b
'Task'
)
and
data
.
find
(
b
'succeeded'
):
break
time
.
sleep
(
0.
2
)
time
.
sleep
(
0.
1
)
task_log_f
.
close
()
thread
=
threading
.
Thread
(
target
=
func
)
thread
.
start
()
...
...
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