Remove handling of runner timeouts
This commit is contained in:

committed by
Sebastian Serth

parent
7ff65135b5
commit
fc6aa12b0a
@@ -1,5 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationJob < ActiveJob::Base
|
||||
queue_as :default
|
||||
end
|
@@ -1,18 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RunnerCleanupJob < ApplicationJob
|
||||
CLEANUP_INTERVAL = CodeOcean::Config.new(:code_ocean).read[:runner_management][:cleanup_interval].seconds
|
||||
|
||||
after_perform do |_job|
|
||||
# re-schedule job
|
||||
self.class.set(wait: CLEANUP_INTERVAL).perform_later
|
||||
end
|
||||
|
||||
def perform
|
||||
Rails.logger.debug(Time.zone.now)
|
||||
Runner.inactive_runners.each do |runner|
|
||||
Rails.logger.debug("Destroying runner #{runner.runner_id}, unused since #{runner.last_used}")
|
||||
runner.destroy
|
||||
end
|
||||
end
|
||||
end
|
@@ -15,14 +15,10 @@ class Runner < ApplicationRecord
|
||||
|
||||
validates :execution_environment, presence: true
|
||||
validates :user, presence: true
|
||||
validates :time_limit, presence: true
|
||||
|
||||
scope :inactive_runners, -> { where('last_used < ?', Time.zone.now - UNUSED_EXPIRATION_TIME) }
|
||||
|
||||
def self.for(user, exercise)
|
||||
execution_environment = ExecutionEnvironment.find(exercise.execution_environment_id)
|
||||
runner = Runner.find_or_create_by(user: user, execution_environment: execution_environment,
|
||||
time_limit: execution_environment.permitted_execution_time)
|
||||
runner = Runner.find_or_create_by(user: user, execution_environment: execution_environment)
|
||||
|
||||
return runner if runner.save
|
||||
|
||||
@@ -41,7 +37,6 @@ class Runner < ApplicationRecord
|
||||
end
|
||||
|
||||
def execute_command(command)
|
||||
used_now
|
||||
url = "#{runner_url}/execute"
|
||||
response = Faraday.post(url, {command: command}.to_json, HEADERS)
|
||||
if response.status == 404
|
||||
@@ -75,6 +70,7 @@ class Runner < ApplicationRecord
|
||||
|
||||
def new_runner
|
||||
url = "#{BASE_URL}/runners"
|
||||
time_limit = CodeOcean::Config.new(:code_ocean)[:runner_management][:unused_runner_expiration_time]
|
||||
body = {executionEnvironmentId: execution_environment.id, timeLimit: time_limit}
|
||||
response = Faraday.post(url, body.to_json, HEADERS)
|
||||
response_body = parse response
|
||||
@@ -89,9 +85,4 @@ class Runner < ApplicationRecord
|
||||
def parse(response)
|
||||
JSON.parse(response.body).deep_symbolize_keys
|
||||
end
|
||||
|
||||
def used_now
|
||||
self.last_used = Time.zone.now
|
||||
save
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user