Remove handling of runner timeouts

This commit is contained in:
Felix Auringer
2021-05-19 16:02:32 +02:00
committed by Sebastian Serth
parent 7ff65135b5
commit fc6aa12b0a
6 changed files with 7 additions and 46 deletions

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
queue_as :default
end

View File

@ -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

View File

@ -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

View File

@ -1,3 +0,0 @@
# frozen_string_literal: true
RunnerCleanupJob.perform_now unless Rake.application.top_level_tasks.to_s.match?(/db:|assets:/)

View File

@ -1,12 +1,10 @@
class CreateRunners < ActiveRecord::Migration[5.2]
class CreateRunners < ActiveRecord::Migration[6.1]
def change
create_table :runners do |t|
t.string :runner_id
t.references :execution_environment
t.references :user, polymorphic: true
t.integer :time_limit
t.float :waiting_time
t.datetime :last_used
t.timestamps
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_12_133612) do
ActiveRecord::Schema.define(version: 2021_05_19_134938) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@ -344,13 +344,11 @@ ActiveRecord::Schema.define(version: 2021_05_12_133612) do
t.bigint "execution_environment_id"
t.string "user_type"
t.bigint "user_id"
t.integer "time_limit"
t.float "waiting_time"
t.datetime "last_used"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["execution_environment_id"], name: "index_runners_on_execution_environment_id"
t.index ["user_type", "user_id"], name: "index_runners_on_user_type_and_user_id"
t.index ["user_type", "user_id"], name: "index_runners_on_user"
end
create_table "searches", id: :serial, force: :cascade do |t|