Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.toolbox
Commits
0e91a8db
Commit
0e91a8db
authored
Feb 02, 2015
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
equeue: realtime logging.
parent
1b5dd613
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
5 deletions
+41
-5
slapos/equeue/__init__.py
slapos/equeue/__init__.py
+41
-5
No files found.
slapos/equeue/__init__.py
View file @
0e91a8db
...
...
@@ -42,6 +42,38 @@ import SocketServer
import
StringIO
import
threading
# Copied from erp5.util:erp5/util/testnode/ProcessManager.py
def
subprocess_capture
(
p
,
log
,
log_prefix
,
get_output
=
True
):
def
readerthread
(
input
,
output
,
buffer
):
while
True
:
data
=
input
.
readline
()
if
not
data
:
break
if
get_output
:
buffer
.
append
(
data
)
if
log_prefix
:
data
=
"%s : "
%
log_prefix
+
data
data
=
data
.
rstrip
(
'
\
n
'
)
output
(
data
)
if
p
.
stdout
:
stdout
=
[]
stdout_thread
=
threading
.
Thread
(
target
=
readerthread
,
args
=
(
p
.
stdout
,
log
,
stdout
))
stdout_thread
.
daemon
=
True
stdout_thread
.
start
()
if
p
.
stderr
:
stderr
=
[]
stderr_thread
=
threading
.
Thread
(
target
=
readerthread
,
args
=
(
p
.
stderr
,
log
,
stderr
))
stderr_thread
.
daemon
=
True
stderr_thread
.
start
()
p
.
wait
()
if
p
.
stdout
:
stdout_thread
.
join
()
if
p
.
stderr
:
stderr_thread
.
join
()
return
(
p
.
stdout
and
''
.
join
(
stdout
),
p
.
stderr
and
''
.
join
(
stderr
))
class
EqueueServer
(
SocketServer
.
ThreadingUnixStreamServer
):
...
...
@@ -84,11 +116,15 @@ class EqueueServer(SocketServer.ThreadingUnixStreamServer):
self
.
logger
.
info
(
"Running %s, %s with output:"
,
cmd_readable
,
timestamp
)
try
:
self
.
logger
.
info
(
subprocess
.
check_output
(
cmd_list
,
stderr
=
subprocess
.
STDOUT
)
)
self
.
logger
.
info
(
"%s finished successfully."
,
cmd_readable
)
self
.
db
[
cmd_executable
]
=
str
(
timestamp
)
sys
.
stdout
.
flush
()
p
=
subprocess
.
Popen
(
cmd_list
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
subprocess_capture
(
p
,
self
.
logger
.
info
,
''
,
True
)
if
p
.
returncode
==
0
:
self
.
logger
.
info
(
"%s finished successfully."
,
cmd_readable
)
self
.
db
[
cmd_executable
]
=
str
(
timestamp
)
else
:
self
.
logger
.
warning
(
"%s exited with status %s."
%
(
cmd_readable
,
p
.
returncode
))
except
subprocess
.
CalledProcessError
as
e
:
self
.
logger
.
warning
(
"%s exited with status %s. output is:
\
n
%s"
%
(
cmd_readable
,
...
...
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