|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require 'find'
|
2 | 4 | require 'pathname'
|
3 | 5 | require 'recursive_yaml_reader'
|
@@ -97,44 +99,42 @@ def refresh_course(course, options)
|
97 | 99 | # I prefer suggestion 1.
|
98 | 100 |
|
99 | 101 | Course.transaction(requires_new: true) do
|
100 |
| - begin |
101 |
| - @course = Course.lock(true).find(course.id) |
102 |
| - |
103 |
| - @old_cache_path = @course.cache_path |
104 |
| - |
105 |
| - @course.increment_cache_version unless options[:no_directory_changes] # causes @course.*_path to return paths in the new cache |
106 |
| - |
107 |
| - FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes] |
108 |
| - FileUtils.mkdir_p(@course.cache_path) unless options[:no_directory_changes] |
109 |
| - |
110 |
| - measure_and_log :update_or_clone_repository unless options[:no_directory_changes] |
111 |
| - measure_and_log :check_directory_names unless options[:no_directory_changes] |
112 |
| - measure_and_log :update_course_options |
113 |
| - measure_and_log :add_records_for_new_exercises |
114 |
| - measure_and_log :delete_records_for_removed_exercises |
115 |
| - measure_and_log :update_exercise_options |
116 |
| - measure_and_log :set_has_tests_flags |
117 |
| - measure_and_log :update_available_points, options[:no_directory_changes] unless options[:no_background_operations] |
118 |
| - measure_and_log :make_solutions unless options[:no_directory_changes] |
119 |
| - measure_and_log :make_stubs unless options[:no_directory_changes] |
120 |
| - measure_and_log :checksum_stubs |
121 |
| - measure_and_log :make_zips_of_stubs unless options[:no_directory_changes] |
122 |
| - measure_and_log :make_zips_of_solutions unless options[:no_directory_changes] |
123 |
| - measure_and_log :set_permissions unless options[:no_directory_changes] |
124 |
| - measure_and_log :invalidate_unlocks |
125 |
| - |
126 |
| - @course.course_template.save! |
127 |
| - @course.refreshed_at = Time.now |
128 |
| - @course.save! |
129 |
| - @course.exercises.each &:save! |
130 |
| - |
131 |
| - CourseRefresher.simulate_failure! if ::Rails.env.test? && CourseRefresher.respond_to?('simulate_failure!') |
132 |
| - rescue StandardError, ScriptError # Some YAML parsers throw ScriptError on syntax errors |
133 |
| - @report.errors << $!.message + "\n" + $!.backtrace.join("\n") |
134 |
| - # Delete the new cache we were working on |
135 |
| - FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes] |
136 |
| - raise ActiveRecord::Rollback |
137 |
| - end |
| 102 | + @course = Course.lock(true).find(course.id) |
| 103 | + |
| 104 | + @old_cache_path = @course.cache_path |
| 105 | + |
| 106 | + @course.increment_cache_version unless options[:no_directory_changes] # causes @course.*_path to return paths in the new cache |
| 107 | + |
| 108 | + FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes] |
| 109 | + FileUtils.mkdir_p(@course.cache_path) unless options[:no_directory_changes] |
| 110 | + |
| 111 | + measure_and_log :update_or_clone_repository unless options[:no_directory_changes] |
| 112 | + measure_and_log :check_directory_names unless options[:no_directory_changes] |
| 113 | + measure_and_log :update_course_options |
| 114 | + measure_and_log :add_records_for_new_exercises |
| 115 | + measure_and_log :delete_records_for_removed_exercises |
| 116 | + measure_and_log :update_exercise_options |
| 117 | + measure_and_log :set_has_tests_flags |
| 118 | + measure_and_log :update_available_points, options[:no_directory_changes] unless options[:no_background_operations] |
| 119 | + measure_and_log :make_solutions unless options[:no_directory_changes] |
| 120 | + measure_and_log :make_stubs unless options[:no_directory_changes] |
| 121 | + measure_and_log :checksum_stubs |
| 122 | + measure_and_log :make_zips_of_stubs unless options[:no_directory_changes] |
| 123 | + measure_and_log :make_zips_of_solutions unless options[:no_directory_changes] |
| 124 | + measure_and_log :set_permissions unless options[:no_directory_changes] |
| 125 | + measure_and_log :invalidate_unlocks |
| 126 | + |
| 127 | + @course.course_template.save! |
| 128 | + @course.refreshed_at = Time.now |
| 129 | + @course.save! |
| 130 | + @course.exercises.each &:save! |
| 131 | + |
| 132 | + CourseRefresher.simulate_failure! if ::Rails.env.test? && CourseRefresher.respond_to?('simulate_failure!') |
| 133 | + rescue StandardError, ScriptError # Some YAML parsers throw ScriptError on syntax errors |
| 134 | + @report.errors << $!.message + "\n" + $!.backtrace.join("\n") |
| 135 | + # Delete the new cache we were working on |
| 136 | + FileUtils.rm_rf(@course.cache_path) unless options[:no_directory_changes] |
| 137 | + raise ActiveRecord::Rollback |
138 | 138 | end
|
139 | 139 |
|
140 | 140 | if @report.errors.empty? && !options[:no_directory_changes]
|
@@ -236,24 +236,22 @@ def update_exercise_options
|
236 | 236 | reader = RecursiveYamlReader.new
|
237 | 237 | @review_points = {}
|
238 | 238 | @course.exercises.each do |e|
|
239 |
| - begin |
240 |
| - metadata = reader.read_settings(root_dir: @course.clone_path, |
241 |
| - target_dir: File.join(@course.clone_path, e.relative_path), |
242 |
| - file_name: 'metadata.yml', |
243 |
| - defaults: Exercise.default_options, |
244 |
| - file_preprocessor: proc do |opts| |
245 |
| - merge_course_specific_suboptions(opts) |
246 |
| - end) |
247 |
| - @review_points[e.name] = parse_review_points(metadata['review_points']) |
248 |
| - |
249 |
| - e.options = metadata |
250 |
| - |
251 |
| - e.disabled! if e.new_record? && e.course.refreshed? |
252 |
| - |
253 |
| - e.save! |
254 |
| - rescue SyntaxError |
255 |
| - @report.errors << "Failed to parse metadata: #{$!}" |
256 |
| - end |
| 239 | + metadata = reader.read_settings(root_dir: @course.clone_path, |
| 240 | + target_dir: File.join(@course.clone_path, e.relative_path), |
| 241 | + file_name: 'metadata.yml', |
| 242 | + defaults: Exercise.default_options, |
| 243 | + file_preprocessor: proc do |opts| |
| 244 | + merge_course_specific_suboptions(opts) |
| 245 | + end) |
| 246 | + @review_points[e.name] = parse_review_points(metadata['review_points']) |
| 247 | + |
| 248 | + e.options = metadata |
| 249 | + |
| 250 | + e.disabled! if e.new_record? && e.course.refreshed? |
| 251 | + |
| 252 | + e.save! |
| 253 | + rescue SyntaxError |
| 254 | + @report.errors << "Failed to parse metadata: #{$!}" |
257 | 255 | end
|
258 | 256 | end
|
259 | 257 |
|
|
0 commit comments