Use switch_locale instead of I18n.with_locale directly
This commit is contained in:
@ -4,11 +4,9 @@ require 'concurrent/future'
|
|||||||
|
|
||||||
module SubmissionScoring
|
module SubmissionScoring
|
||||||
def collect_test_results(submission)
|
def collect_test_results(submission)
|
||||||
current_locale = I18n.locale
|
|
||||||
# Mnemosyne.trace 'custom.codeocean.collect_test_results', meta: { submission: submission.id } do
|
# Mnemosyne.trace 'custom.codeocean.collect_test_results', meta: { submission: submission.id } do
|
||||||
futures = submission.collect_files.select(&:teacher_defined_assessment?).map do |file|
|
futures = submission.collect_files.select(&:teacher_defined_assessment?).map do |file|
|
||||||
Concurrent::Future.execute do
|
Concurrent::Future.execute do
|
||||||
I18n.with_locale(current_locale) do
|
|
||||||
# Mnemosyne.trace 'custom.codeocean.collect_test_results_block', meta: { file: file.id, submission: submission.id } 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)
|
assessor = Assessor.new(execution_environment: submission.execution_environment)
|
||||||
output = execute_test_file(file, submission)
|
output = execute_test_file(file, submission)
|
||||||
@ -37,18 +35,17 @@ module SubmissionScoring
|
|||||||
LinterCheckRun.create_from(testrun, assessment)
|
LinterCheckRun.create_from(testrun, assessment)
|
||||||
switch_locale do
|
switch_locale do
|
||||||
assessment = assessor.translate_linter(assessment, I18n.locale)
|
assessment = assessor.translate_linter(assessment, I18n.locale)
|
||||||
end
|
|
||||||
|
|
||||||
# replace file name with hint if linter is not used for grading. Refactor!
|
# replace file name with hint if linter is not used for grading. Refactor!
|
||||||
filename = t('exercises.implement.not_graded') if file.weight.zero?
|
filename = t('exercises.implement.not_graded') if file.weight.zero?
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
output.merge!(assessment)
|
output.merge!(assessment)
|
||||||
output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight)
|
output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight)
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
futures.map(&:value)
|
futures.map(&:value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -366,16 +366,13 @@ class SubmissionsController < ApplicationController
|
|||||||
|
|
||||||
# the score_submission call will end up calling docker exec, which is blocking.
|
# the score_submission call will end up calling docker exec, which is blocking.
|
||||||
# to ensure responsiveness, we therefore open a thread here.
|
# to ensure responsiveness, we therefore open a thread here.
|
||||||
current_locale = I18n.locale
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
I18n.with_locale(current_locale) do
|
|
||||||
tubesock.send_data JSON.dump(score_submission(@submission))
|
tubesock.send_data JSON.dump(score_submission(@submission))
|
||||||
|
|
||||||
# To enable hints when scoring a submission, uncomment the next line:
|
# To enable hints when scoring a submission, uncomment the next line:
|
||||||
# send_hints(tubesock, StructuredError.where(submission: @submission))
|
# send_hints(tubesock, StructuredError.where(submission: @submission))
|
||||||
|
|
||||||
tubesock.send_data JSON.dump({'cmd' => 'exit'})
|
tubesock.send_data JSON.dump({'cmd' => 'exit'})
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.connection_pool.release_connection
|
ActiveRecord::Base.connection_pool.release_connection
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user