diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb deleted file mode 100644 index 97fc265f..00000000 --- a/app/jobs/application_job.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class ApplicationJob < ActiveJob::Base - queue_as :default -end diff --git a/app/jobs/runner_cleanup_job.rb b/app/jobs/runner_cleanup_job.rb deleted file mode 100644 index f578e9d5..00000000 --- a/app/jobs/runner_cleanup_job.rb +++ /dev/null @@ -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 diff --git a/app/models/runner.rb b/app/models/runner.rb index 653bc886..cb566661 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -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 diff --git a/config/initializers/jobs.rb b/config/initializers/jobs.rb deleted file mode 100644 index f4bf7be2..00000000 --- a/config/initializers/jobs.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -RunnerCleanupJob.perform_now unless Rake.application.top_level_tasks.to_s.match?(/db:|assets:/) diff --git a/db/migrate/20210415064948_create_runners.rb b/db/migrate/20210519134938_create_runners.rb similarity index 67% rename from db/migrate/20210415064948_create_runners.rb rename to db/migrate/20210519134938_create_runners.rb index 3ebebb63..e747ed4a 100644 --- a/db/migrate/20210415064948_create_runners.rb +++ b/db/migrate/20210519134938_create_runners.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b899981c..fb4dbc1d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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|