From 2c08e270e7045bb39ee1be59944abd99942a3f2a Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Thu, 5 Aug 2021 11:55:54 +0200 Subject: [PATCH] Revert "Use switch_locale instead of I18n.with_locale directly" This reverts commit 125c342f35d425a8d6dbb9f09d6939c06bc8c947. --- .../concerns/submission_scoring.rb | 61 ++++++++++--------- app/controllers/submissions_controller.rb | 11 ++-- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index da28520a..b6e1aa08 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -4,46 +4,49 @@ require 'concurrent/future' module SubmissionScoring def collect_test_results(submission) + current_locale = I18n.locale # Mnemosyne.trace 'custom.codeocean.collect_test_results', meta: { submission: submission.id } do futures = submission.collect_files.select(&:teacher_defined_assessment?).map do |file| Concurrent::Future.execute do - # Mnemosyne.trace 'custom.codeocean.collect_test_results_block', meta: { file: file.id, submission: submission.id } do - assessor = Assessor.new(execution_environment: submission.execution_environment) - output = execute_test_file(file, submission) - assessment = assessor.assess(output) - passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?) - testrun_output = passed ? nil : "status: #{output[:status]}\n stdout: #{output[:stdout]}\n stderr: #{output[:stderr]}" - if testrun_output.present? - submission.exercise.execution_environment.error_templates.each do |template| - pattern = Regexp.new(template.signature).freeze - StructuredError.create_from_template(template, testrun_output, submission) if pattern.match(testrun_output) + I18n.with_locale(current_locale) do + # Mnemosyne.trace 'custom.codeocean.collect_test_results_block', meta: { file: file.id, submission: submission.id } do + assessor = Assessor.new(execution_environment: submission.execution_environment) + output = execute_test_file(file, submission) + assessment = assessor.assess(output) + passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?) + testrun_output = passed ? nil : "status: #{output[:status]}\n stdout: #{output[:stdout]}\n stderr: #{output[:stderr]}" + if testrun_output.present? + submission.exercise.execution_environment.error_templates.each do |template| + pattern = Regexp.new(template.signature).freeze + StructuredError.create_from_template(template, testrun_output, submission) if pattern.match(testrun_output) + end end - end - testrun = Testrun.create( - submission: submission, - cause: 'assess', # Required to differ run and assess for RfC show - file: file, # Test file that was executed - passed: passed, - output: testrun_output, - container_execution_time: output[:container_execution_time], - waiting_for_container_time: output[:waiting_for_container_time] - ) + testrun = Testrun.create( + submission: submission, + cause: 'assess', # Required to differ run and assess for RfC show + file: file, # Test file that was executed + passed: passed, + output: testrun_output, + container_execution_time: output[:container_execution_time], + waiting_for_container_time: output[:waiting_for_container_time] + ) - filename = file.name_with_extension + filename = file.name_with_extension - if file.teacher_defined_linter? - LinterCheckRun.create_from(testrun, assessment) - switch_locale do - assessment = assessor.translate_linter(assessment, I18n.locale) + if file.teacher_defined_linter? + LinterCheckRun.create_from(testrun, assessment) + switch_locale do + assessment = assessor.translate_linter(assessment, I18n.locale) + end # replace file name with hint if linter is not used for grading. Refactor! filename = t('exercises.implement.not_graded') if file.weight.zero? end - end - output.merge!(assessment) - output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight) - # end + output.merge!(assessment) + output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight) + # end + end end end futures.map(&:value) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index fc70f5a8..f97d89b0 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -366,13 +366,16 @@ class SubmissionsController < ApplicationController # the score_submission call will end up calling docker exec, which is blocking. # to ensure responsiveness, we therefore open a thread here. + current_locale = I18n.locale Thread.new do - tubesock.send_data JSON.dump(score_submission(@submission)) + I18n.with_locale(current_locale) do + tubesock.send_data JSON.dump(score_submission(@submission)) - # To enable hints when scoring a submission, uncomment the next line: - # send_hints(tubesock, StructuredError.where(submission: @submission)) + # To enable hints when scoring a submission, uncomment the next line: + # send_hints(tubesock, StructuredError.where(submission: @submission)) - tubesock.send_data JSON.dump({'cmd' => 'exit'}) + tubesock.send_data JSON.dump({'cmd' => 'exit'}) + end ensure ActiveRecord::Base.connection_pool.release_connection end