Persist Execution Environment when running code
This commit is contained in:
@ -293,7 +293,7 @@ class SubmissionsController < ApplicationController
|
|||||||
|
|
||||||
# save the output of this "run" as a "testrun" (scoring runs are saved in submission.rb)
|
# save the output of this "run" as a "testrun" (scoring runs are saved in submission.rb)
|
||||||
def save_run_output
|
def save_run_output
|
||||||
Testrun.create(
|
testrun = Testrun.create(
|
||||||
file: @file,
|
file: @file,
|
||||||
cause: 'run',
|
cause: 'run',
|
||||||
submission: @submission,
|
submission: @submission,
|
||||||
@ -301,6 +301,7 @@ class SubmissionsController < ApplicationController
|
|||||||
container_execution_time: @container_execution_time,
|
container_execution_time: @container_execution_time,
|
||||||
waiting_for_container_time: @waiting_for_container_time
|
waiting_for_container_time: @waiting_for_container_time
|
||||||
)
|
)
|
||||||
|
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @submission.used_execution_environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_hints(tubesock, errors)
|
def send_hints(tubesock, errors)
|
||||||
|
@ -16,6 +16,7 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
has_many :exercises
|
has_many :exercises
|
||||||
belongs_to :file_type
|
belongs_to :file_type
|
||||||
has_many :error_templates
|
has_many :error_templates
|
||||||
|
belongs_to :testrun_execution_environment, optional: true, dependent: :destroy
|
||||||
|
|
||||||
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }
|
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ class Submission < ApplicationRecord
|
|||||||
|
|
||||||
validates :cause, inclusion: {in: CAUSES}
|
validates :cause, inclusion: {in: CAUSES}
|
||||||
|
|
||||||
|
attr_reader :used_execution_environment
|
||||||
|
|
||||||
# after_save :trigger_working_times_action_cable
|
# after_save :trigger_working_times_action_cable
|
||||||
|
|
||||||
def build_files_hash(files, attribute)
|
def build_files_hash(files, attribute)
|
||||||
@ -195,8 +197,8 @@ class Submission < ApplicationRecord
|
|||||||
def prepared_runner
|
def prepared_runner
|
||||||
request_time = Time.zone.now
|
request_time = Time.zone.now
|
||||||
begin
|
begin
|
||||||
execution_environment = AwsStudy.get_execution_environment(user, exercise)
|
@used_execution_environment = AwsStudy.get_execution_environment(user, exercise)
|
||||||
runner = Runner.for(user, execution_environment)
|
runner = Runner.for(user, @used_execution_environment)
|
||||||
files = collect_files
|
files = collect_files
|
||||||
files.reject!(&:teacher_defined_assessment?) if cause == 'run'
|
files.reject!(&:teacher_defined_assessment?) if cause == 'run'
|
||||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Copying files to Runner #{runner.id} for #{user_type} #{user_id} and Submission #{id}." }
|
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Copying files to Runner #{runner.id} for #{user_type} #{user_id} and Submission #{id}." }
|
||||||
@ -254,6 +256,7 @@ class Submission < ApplicationRecord
|
|||||||
container_execution_time: output[:container_execution_time],
|
container_execution_time: output[:container_execution_time],
|
||||||
waiting_for_container_time: output[:waiting_for_container_time]
|
waiting_for_container_time: output[:waiting_for_container_time]
|
||||||
)
|
)
|
||||||
|
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @used_execution_environment)
|
||||||
|
|
||||||
filename = file.filepath
|
filename = file.filepath
|
||||||
|
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
class Testrun < ApplicationRecord
|
class Testrun < ApplicationRecord
|
||||||
belongs_to :file, class_name: 'CodeOcean::File', optional: true
|
belongs_to :file, class_name: 'CodeOcean::File', optional: true
|
||||||
belongs_to :submission
|
belongs_to :submission
|
||||||
|
belongs_to :testrun_execution_environment, optional: true, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
6
app/models/testrun_execution_environment.rb
Normal file
6
app/models/testrun_execution_environment.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class TestrunExecutionEnvironment < ApplicationRecord
|
||||||
|
belongs_to :testrun
|
||||||
|
belongs_to :execution_environment
|
||||||
|
end
|
@ -0,0 +1,12 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddTestrunExecutionEnvironment < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :testrun_execution_environments do |t|
|
||||||
|
t.belongs_to :testrun, foreign_key: true, null: false, index: true
|
||||||
|
t.belongs_to :execution_environment, foreign_key: true, null: false, index: {name: 'index_testrun_execution_environments'}
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
db/schema.rb
13
db/schema.rb
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_11_18_185051) do
|
ActiveRecord::Schema.define(version: 2022_04_15_125948) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
@ -461,6 +461,15 @@ ActiveRecord::Schema.define(version: 2021_11_18_185051) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "testrun_execution_environments", force: :cascade do |t|
|
||||||
|
t.bigint "testrun_id", null: false
|
||||||
|
t.bigint "execution_environment_id", 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_testrun_execution_environments"
|
||||||
|
t.index ["testrun_id"], name: "index_testrun_execution_environments_on_testrun_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "testruns", id: :serial, force: :cascade do |t|
|
create_table "testruns", id: :serial, force: :cascade do |t|
|
||||||
t.boolean "passed"
|
t.boolean "passed"
|
||||||
t.text "output"
|
t.text "output"
|
||||||
@ -536,6 +545,8 @@ ActiveRecord::Schema.define(version: 2021_11_18_185051) do
|
|||||||
add_foreign_key "exercise_tips", "tips"
|
add_foreign_key "exercise_tips", "tips"
|
||||||
add_foreign_key "remote_evaluation_mappings", "study_groups"
|
add_foreign_key "remote_evaluation_mappings", "study_groups"
|
||||||
add_foreign_key "submissions", "study_groups"
|
add_foreign_key "submissions", "study_groups"
|
||||||
|
add_foreign_key "testrun_execution_environments", "execution_environments"
|
||||||
|
add_foreign_key "testrun_execution_environments", "testruns"
|
||||||
add_foreign_key "tips", "file_types"
|
add_foreign_key "tips", "file_types"
|
||||||
add_foreign_key "user_exercise_feedbacks", "submissions"
|
add_foreign_key "user_exercise_feedbacks", "submissions"
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user