Rework protocol inside websocket
Co-authored-by Felix Auringer <felix.auringer@student.hpi.uni-potsdam.de>
This commit is contained in:

committed by
Sebastian Serth

parent
6a4e302f4e
commit
347e4728a0
@ -4,6 +4,9 @@ require 'container_connection'
|
||||
|
||||
class Container
|
||||
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:container_management][:url]
|
||||
HEADERS = {"Content-Type" => "application/json"}
|
||||
|
||||
attr_accessor :waiting_time
|
||||
|
||||
def initialize(execution_environment, time_limit = nil)
|
||||
url = "#{BASE_URL}/execution-environments/#{execution_environment.id}/containers/create"
|
||||
@ -11,7 +14,7 @@ class Container
|
||||
if time_limit
|
||||
body[:time_limit] = time_limit
|
||||
end
|
||||
response = Faraday.post(url, body.to_json, "Content-Type" => "application/json")
|
||||
response = Faraday.post(url, body.to_json, HEADERS)
|
||||
response = parse response
|
||||
@container_id = response[:id]
|
||||
end
|
||||
@ -19,7 +22,7 @@ class Container
|
||||
def copy_files(files)
|
||||
url = container_url + "/files"
|
||||
body = files.map{ |filename, content| { filename => content } }
|
||||
Faraday.post(url, body.to_json, "Content-Type" => "application/json")
|
||||
Faraday.post(url, body.to_json, HEADERS)
|
||||
end
|
||||
|
||||
def copy_submission_files(submission)
|
||||
@ -32,17 +35,19 @@ class Container
|
||||
|
||||
def execute_command(command)
|
||||
url = container_url + "/execute"
|
||||
response = Faraday.patch(url, {command: command}.to_json, "Content-Type" => "application/json")
|
||||
response = Faraday.patch(url, {command: command}.to_json, HEADERS)
|
||||
response = parse response
|
||||
response
|
||||
end
|
||||
|
||||
def execute_interactively(command)
|
||||
starting_time = Time.now
|
||||
websocket_url = execute_command(command)[:websocket_url]
|
||||
EventMachine.run do
|
||||
socket = ContainerConnection.new(websocket_url)
|
||||
yield(self, socket) if block_given?
|
||||
end
|
||||
Time.now - starting_time # execution time
|
||||
end
|
||||
|
||||
def destroy
|
||||
@ -50,7 +55,7 @@ class Container
|
||||
end
|
||||
|
||||
def status
|
||||
parse(Faraday.get(container_url))[:status]
|
||||
parse(Faraday.get(container_url))[:status].to_sym
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user