Skip to content

Commit

Permalink
Fix webservice
Browse files Browse the repository at this point in the history
We're using the WSGIServer from gevent in order to integrate websockets easily,
but that server is not talking fcgi. Luckily we could skip lighttpd altogether
using the generic webservice type on the Tool Labs grid engine.
  • Loading branch information
danmichaelo committed Jan 7, 2018
1 parent 3ab18f6 commit 7ef65ba
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 35 deletions.
17 changes: 0 additions & 17 deletions .lighttpd.conf

This file was deleted.

1 change: 1 addition & 0 deletions server.sh
@@ -1,3 +1,4 @@
#!/bin/sh
export APP_BASE_HREF=https://tools.wmflabs.org/ukbot/
. ENV/bin/activate
python -m src.server
6 changes: 6 additions & 0 deletions service.manifest
@@ -0,0 +1,6 @@
# This file is used by toollabs infrastructure.
# Please do not edit manually at this time.
backend: gridengine
version: 2
web: generic
web::extra_args: /data/project/ukbot/server.sh
11 changes: 8 additions & 3 deletions src/server.py
Expand Up @@ -2,7 +2,6 @@
import os, sys
sys.path.insert(0, '/data/project/ukbot/ENV/lib/python3.4/site-packages')

from flipflop import WSGIServer
from .webinterface.app import app

import logging
Expand All @@ -24,8 +23,14 @@
#app.debug = True # reload on each code change

if __name__ == '__main__':
from gevent import pywsgi
from gevent import pywsgi, socket
from geventwebsocket.handler import WebSocketHandler
server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)

PORT=int(os.environ.get('PORT')) # Tool Forge tells us what port we can use
listener = ('', PORT)

server = pywsgi.WSGIServer(listener, app, handler_class=WebSocketHandler)
server.serve_forever()



10 changes: 5 additions & 5 deletions src/webinterface/app.py
Expand Up @@ -67,7 +67,7 @@ def db_cursor():
db.close()


app = Flask(__name__)
app = Flask(__name__, static_url_path='/ukbot/static')
sockets = Sockets(app)

def error_404():
Expand All @@ -88,7 +88,7 @@ def read_status(fname):
stat = '<em>Failed</em>'
return stat

@app.route('/')
@app.route('/ukbot/')
def show_index():

cf = copy(contests)
Expand Down Expand Up @@ -122,15 +122,15 @@ def show_index():
# )


@app.route('/<contest>/status')
@app.route('/ukbot/<contest>/status')
def show_uk_log(contest):
if contest not in [c['id'] for c in contests]:
return error_404()

return render_template('status.html', base_href=base_href, contest=contest)


@sockets.route('/<contest>/status.sock')
@sockets.route('/ukbot/<contest>/status.sock')
def show_contest_status_sock(socket, contest):
if contest not in [c['id'] for c in contests]:
return error_404()
Expand Down Expand Up @@ -205,7 +205,7 @@ def validate(data):
return page, errors


@app.route('/wordcount')
@app.route('/ukbot/wordcount')
def show_wordcount():
lang = request.args.get('lang', '')
page = request.args.get('page', '')
Expand Down
2 changes: 1 addition & 1 deletion src/webinterface/templates/layout.html
Expand Up @@ -18,7 +18,7 @@
<body>
<div class="container">
<h1>
<a href="/">UKB</a>
<a href="./">UKB</a>
@ Toolforge
</h1>

Expand Down
2 changes: 1 addition & 1 deletion src/webinterface/templates/main.html
Expand Up @@ -13,7 +13,7 @@
<section style="clear:both;">
<img src="static/plots/{{ conf.id }}.mem.png" style="width:400px; float:right;">
<h2>
<a href="./{{ conf.url }}/">{{ conf.name }}</a>
<a href="{{ conf.url }}/">{{ conf.name }}</a>
</h2>
<a href="./{{ conf.id }}/status">{{ conf.status | safe }}</a>
</section>
Expand Down
9 changes: 1 addition & 8 deletions src/webinterface/templates/status.html
Expand Up @@ -8,24 +8,17 @@

<script>

var baseHref = document.getElementsByTagName('base')[0].href.replace(/https?:/, 'ws:');
var baseHref = document.getElementsByTagName('base')[0].href.replace(/https?:/, 'wss:');
var contest = "{{contest}}";

var socket = new WebSocket(baseHref + contest + "/status.sock");
socket.onopen = function(){
console.log("Socket has been opened!");
socket.send('Hello');
// setInterval(function() {
// socket.send('ping');
// }, 1000);

}
socket.onmessage = function(msg){
$('#run_log').text( $('#run_log').text() + msg.data);
console.log(msg); //Awesome!
}


</script>

{% endblock %}

0 comments on commit 7ef65ba

Please sign in to comment.