Show correct timeout message on timeout. Do not show a message on valid exit.
This commit is contained in:
@ -30,7 +30,7 @@ $(function() {
|
||||
numMessages = 0,
|
||||
turtlecanvas = $('#turtlecanvas'),
|
||||
prompt = $('#prompt'),
|
||||
commands = ['input', 'write', 'turtle', 'turtlebatch', 'exit', 'status'],
|
||||
commands = ['input', 'write', 'turtle', 'turtlebatch', 'exit', 'timeout', 'status'],
|
||||
streams = ['stdin', 'stdout', 'stderr'];
|
||||
|
||||
var ENTER_KEY_CODE = 13;
|
||||
@ -1004,7 +1004,7 @@ $(function() {
|
||||
};
|
||||
|
||||
var showTimeoutMessage = function() {
|
||||
$.flash.danger({
|
||||
$.flash.info({
|
||||
icon: ['fa', 'fa-clock-o'],
|
||||
text: $('#editor').data('message-timeout')
|
||||
});
|
||||
@ -1059,14 +1059,6 @@ $(function() {
|
||||
running = false;
|
||||
toggleButtonStates();
|
||||
hidePrompt();
|
||||
flashKillMessage();
|
||||
}
|
||||
|
||||
var flashKillMessage = function() {
|
||||
$.flash.info({
|
||||
icon: ['fa', 'fa-clock-o'],
|
||||
text: "Your program was stopped." // todo get data attribute
|
||||
});
|
||||
}
|
||||
|
||||
// todo set this from websocket command, required to e.g. stop container
|
||||
@ -1176,6 +1168,10 @@ $(function() {
|
||||
case 'exit':
|
||||
killWebsocketAndContainer();
|
||||
break;
|
||||
case 'timeout':
|
||||
// just show the timeout message here. Another exit command is sent by the rails backend when the socket to the docker container closes.
|
||||
showTimeoutMessage();
|
||||
break;
|
||||
case 'status':
|
||||
showStatus(msg)
|
||||
break;
|
||||
|
@ -90,6 +90,12 @@ class SubmissionsController < ApplicationController
|
||||
hijack do |tubesock|
|
||||
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
|
||||
|
||||
|
||||
# socket is the socket into the container, tubesock is the socket to the client
|
||||
|
||||
# give the docker_client the tubesock object, so that it can send messages (timeout)
|
||||
@docker_client.tubesock = tubesock
|
||||
|
||||
result = @docker_client.execute_run_command(@submission, params[:filename])
|
||||
tubesock.send_data JSON.dump({'cmd' => 'status', 'status' => result[:status]})
|
||||
|
||||
|
@ -12,6 +12,7 @@ class DockerClient
|
||||
|
||||
attr_reader :container
|
||||
attr_reader :socket
|
||||
attr_accessor :tubesock
|
||||
|
||||
def self.check_availability!
|
||||
Timeout.timeout(config[:connection_timeout]) { Docker.version }
|
||||
@ -176,6 +177,10 @@ class DockerClient
|
||||
sleep(timeout)
|
||||
if container.status != :returned
|
||||
Rails.logger.info("Killing container after timeout of " + timeout.to_s + " seconds.")
|
||||
# send timeout to the tubesock socket
|
||||
if(@tubesock)
|
||||
@tubesock.send_data JSON.dump({'cmd' => 'timeout'})
|
||||
end
|
||||
kill_container(container)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user