mirror of
https://github.com/openzim/zimit.git
synced 2025-12-31 04:23:15 +00:00
WIP - Stream workers output
This commit is contained in:
parent
a45f56f23a
commit
3450be78fd
8 changed files with 73 additions and 3 deletions
|
|
@ -110,6 +110,7 @@ Nginx configuration
|
||||||
|
|
||||||
# Finally, send all non-media requests to the Pyramid server.
|
# Finally, send all non-media requests to the Pyramid server.
|
||||||
location / {
|
location / {
|
||||||
|
proxy_buffering off
|
||||||
uwsgi_pass zimit_upstream;
|
uwsgi_pass zimit_upstream;
|
||||||
include /var/ideascube/uwsgi_params;
|
include /var/ideascube/uwsgi_params;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
named.py
Normal file
13
named.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def spawn(cmd):
|
||||||
|
os.mkfifo("toto")
|
||||||
|
with open("toto", "w") as f:
|
||||||
|
process = subprocess.Popen(shlex.split(cmd), stdout=f)
|
||||||
|
process.wait()
|
||||||
|
os.unlink("toto")
|
||||||
|
|
||||||
|
spawn("stdbuf -o0 python test.py")
|
||||||
11
readpipe.py
Normal file
11
readpipe.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
def read_fifo(filename):
|
||||||
|
with open(filename) as fifo:
|
||||||
|
while os.path.exists(filename):
|
||||||
|
print(fifo.readline(), end='')
|
||||||
|
|
||||||
|
read_fifo("toto")
|
||||||
6
test.py
Normal file
6
test.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#! /use/bin/python
|
||||||
|
import time
|
||||||
|
|
||||||
|
for i in range(100):
|
||||||
|
time.sleep(0.2)
|
||||||
|
print i
|
||||||
|
|
@ -14,9 +14,11 @@ pyramid.includes =
|
||||||
pyramid_mailer
|
pyramid_mailer
|
||||||
|
|
||||||
[server:main]
|
[server:main]
|
||||||
use = egg:waitress#main
|
use = egg:gunicorn#main
|
||||||
host = 0.0.0.0
|
host = 0.0.0.0
|
||||||
port = 6543
|
port = 6543
|
||||||
|
send_bytes=1
|
||||||
|
worker_class = socketio.sgunicorn.GeventSocketIOWorker
|
||||||
|
|
||||||
# Begin logging configuration
|
# Begin logging configuration
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
@ -13,3 +14,9 @@ def ensure_paths_exists(*paths):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
msg = '%s does not exist.' % path
|
msg = '%s does not exist.' % path
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def read_fifo(filename):
|
||||||
|
with open(filename) as fifo:
|
||||||
|
while os.path.exists(filename):
|
||||||
|
yield fifo.readline()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
from cornice import Service
|
from cornice import Service
|
||||||
from colander import MappingSchema, SchemaNode, String
|
from colander import MappingSchema, SchemaNode, String
|
||||||
|
from pyramid.response import Response
|
||||||
|
|
||||||
|
from zimit import utils
|
||||||
|
|
||||||
webpage = Service(name='website', path='/website')
|
|
||||||
home = Service(name='home', path='/')
|
home = Service(name='home', path='/')
|
||||||
|
webpage = Service(name='website', path='/website')
|
||||||
|
logs = Service(name='home', path='/logs')
|
||||||
|
|
||||||
|
|
||||||
@home.get()
|
@home.get()
|
||||||
|
|
@ -34,4 +38,18 @@ def crawl_new_website(request):
|
||||||
request.validated,
|
request.validated,
|
||||||
timeout=1800)
|
timeout=1800)
|
||||||
request.response.status_code = 201
|
request.response.status_code = 201
|
||||||
return {'success': True}
|
return {
|
||||||
|
'success': True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@logs.get()
|
||||||
|
def get_logs(request):
|
||||||
|
stream_headers = [
|
||||||
|
('Content-Type', 'text/event-stream'),
|
||||||
|
('Cache-Control', 'no-cache')
|
||||||
|
]
|
||||||
|
return Response(
|
||||||
|
headerlist=stream_headers,
|
||||||
|
app_iter=utils.read_fifo("toto")
|
||||||
|
)
|
||||||
|
|
|
||||||
12
zimit/websocket.py
Normal file
12
zimit/websocket.py
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
from socketio import namespace, socketio_manage
|
||||||
|
|
||||||
|
|
||||||
|
class LogsNamespace(namespace.BaseNamespace):
|
||||||
|
def on_read(self, filename):
|
||||||
|
self.emit('chat', "yeah")
|
||||||
|
|
||||||
|
|
||||||
|
def socketio_service(request):
|
||||||
|
socketio_manage(request.environ, {'/logs': LogsNamespace},
|
||||||
|
request)
|
||||||
|
return "out"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue