Persist Execution Environment when running code

This commit is contained in:
Sebastian Serth
2022-04-15 15:16:57 +02:00
parent 4887f4af02
commit d10735d0a8
7 changed files with 39 additions and 4 deletions

View File

@@ -293,7 +293,7 @@ class SubmissionsController < ApplicationController
# save the output of this "run" as a "testrun" (scoring runs are saved in submission.rb)
def save_run_output
Testrun.create(
testrun = Testrun.create(
file: @file,
cause: 'run',
submission: @submission,
@@ -301,6 +301,7 @@ class SubmissionsController < ApplicationController
container_execution_time: @container_execution_time,
waiting_for_container_time: @waiting_for_container_time
)
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @submission.used_execution_environment)
end
def send_hints(tubesock, errors)

View File

@@ -16,6 +16,7 @@ class ExecutionEnvironment < ApplicationRecord
has_many :exercises
belongs_to :file_type
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)') }

View File

@@ -46,6 +46,8 @@ class Submission < ApplicationRecord
validates :cause, inclusion: {in: CAUSES}
attr_reader :used_execution_environment
# after_save :trigger_working_times_action_cable
def build_files_hash(files, attribute)
@@ -195,8 +197,8 @@ class Submission < ApplicationRecord
def prepared_runner
request_time = Time.zone.now
begin
execution_environment = AwsStudy.get_execution_environment(user, exercise)
runner = Runner.for(user, execution_environment)
@used_execution_environment = AwsStudy.get_execution_environment(user, exercise)
runner = Runner.for(user, @used_execution_environment)
files = collect_files
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}." }
@@ -254,6 +256,7 @@ class Submission < ApplicationRecord
container_execution_time: output[:container_execution_time],
waiting_for_container_time: output[:waiting_for_container_time]
)
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @used_execution_environment)
filename = file.filepath

View File

@@ -3,4 +3,5 @@
class Testrun < ApplicationRecord
belongs_to :file, class_name: 'CodeOcean::File', optional: true
belongs_to :submission
belongs_to :testrun_execution_environment, optional: true, dependent: :destroy
end

View File

@@ -0,0 +1,6 @@
# frozen_string_literal: true
class TestrunExecutionEnvironment < ApplicationRecord
belongs_to :testrun
belongs_to :execution_environment
end