diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 0b05f687..3e24af1c 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -202,17 +202,6 @@ class SubmissionsController < ApplicationController tubesock.close end - def extract_errors - unless @raw_output.blank? - @submission.exercise.execution_environment.error_templates.each do |template| - pattern = Regexp.new(template.signature).freeze - if pattern.match(@raw_output) - StructuredError.create_from_template(template, @raw_output) - end - end - end - end - def handle_message(message, tubesock, container) @raw_output ||= '' @run_output ||= '' @@ -289,6 +278,17 @@ class SubmissionsController < ApplicationController end end + def extract_errors + unless @raw_output.blank? + @submission.exercise.execution_environment.error_templates.each do |template| + pattern = Regexp.new(template.signature).freeze + if pattern.match(@raw_output) + StructuredError.create_from_template(template, @raw_output, @submission) + end + end + end + end + def score hijack do |tubesock| Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive? diff --git a/app/models/structured_error.rb b/app/models/structured_error.rb index 2f03ec54..c1f6669c 100644 --- a/app/models/structured_error.rb +++ b/app/models/structured_error.rb @@ -1,9 +1,10 @@ class StructuredError < ActiveRecord::Base belongs_to :error_template + belongs_to :submission belongs_to :file, class_name: 'CodeOcean::File' - def self.create_from_template(template, message_buffer) - instance = self.create(error_template: template) + def self.create_from_template(template, message_buffer, submission) + instance = self.create(error_template: template, submission: submission) template.error_template_attributes.each do |attribute| StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer) end diff --git a/app/models/submission.rb b/app/models/submission.rb index d75d6019..c27d01bd 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -8,6 +8,7 @@ class Submission < ActiveRecord::Base belongs_to :exercise has_many :testruns + has_many :structured_errors has_many :comments, through: :files delegate :execution_environment, to: :exercise diff --git a/db/migrate/20180130101645_add_submission_to_structured_errors.rb b/db/migrate/20180130101645_add_submission_to_structured_errors.rb new file mode 100644 index 00000000..3f7d2a5e --- /dev/null +++ b/db/migrate/20180130101645_add_submission_to_structured_errors.rb @@ -0,0 +1,5 @@ +class AddSubmissionToStructuredErrors < ActiveRecord::Migration + def change + add_reference :structured_errors, :submission, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3ed07240..9ab33939 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171120153705) do +ActiveRecord::Schema.define(version: 20180130101645) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -305,8 +305,11 @@ ActiveRecord::Schema.define(version: 20171120153705) do t.integer "file_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "submission_id" end + add_index "structured_errors", ["submission_id"], name: "index_structured_errors_on_submission_id", using: :btree + create_table "submissions", force: :cascade do |t| t.integer "exercise_id" t.float "score"