also handle testcommand via websocket

This commit is contained in:
Ralf Teusner
2016-06-17 17:23:47 +02:00
parent 96de763b83
commit 7c1be5594a
2 changed files with 14 additions and 7 deletions

View File

@ -350,13 +350,14 @@ $(function() {
flowrOutputBuffer = '';
};
var handleTestResponse = function(response) {
var handleTestResponse = function(websocket_event) {
result = JSON.parse(websocket_event.data);
clearOutput();
printOutput(response[0], false, 0);
printOutput(result, false, 0);
if (qa_api) {
qa_api.executeCommand('syncOutput', [response]);
qa_api.executeCommand('syncOutput', [result]);
}
showStatus(response[0]);
showStatus(result);
showTab(1);
};
@ -956,7 +957,7 @@ $(function() {
createSubmission(this, null, function(response) {
showSpinner($('#test'));
var url = response.test_url.replace(FILENAME_URL_PLACEHOLDER, active_file.filename);
evaluateCode(url, false, handleTestResponse);
evaluateCode(url, true, handleTestResponse);
});
}
};

View File

@ -270,8 +270,14 @@ class SubmissionsController < ApplicationController
private :store_error
def test
output = @docker_client.execute_test_command(@submission, params[:filename])
render(json: [output])
hijack do |tubesock|
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
output = @docker_client.execute_test_command(@submission, params[:filename])
# tubesock is the socket to the client
tubesock.send_data JSON.dump(output)
end
end
def with_server_sent_events