Skip to content

Commit 23bd227

Browse files
committed
feat: auto archive of units is optional
Use new environment variable to enable archive - false by default.
1 parent 9b2cf03 commit 23bd227

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

app/sidekiq/archive_old_units_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class ArchiveOldUnitsJob
55
include Sidekiq::Job
66

77
def perform
8+
return unless Doubtfire::Application.config.archive_units
9+
810
archive_period = Doubtfire::Application.config.unit_archive_after_period
911

1012
archive_period = 1.year if archive_period < 1.year

config/application.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ class Application < Rails::Application
3636
# Set using DF_ARCHIVE_DIR environment variable.
3737
config.archive_dir = ENV.fetch('DF_ARCHIVE_DIR', "#{config.student_work_dir}/archive")
3838

39+
# Allows for the archiving of units to be automated
40+
config.archive_units = ENV['DF_ARCHIVE_UNITS'].present? && (ENV['DF_ARCHIVE_UNITS'].to_s.downcase == "true" || ENV['DF_ARCHIVE_UNITS'].to_i == 1)
41+
42+
# Period for which to keep units
43+
config.unit_archive_after_period = ENV.fetch('DF_UNIT_ARCHIVE_PERIOD', 2).to_f * 1.year
44+
3945
# Limit number of pdf generators to run at once
4046
config.pdfgen_max_processes = ENV['DF_MAX_PDF_GEN_PROCESSES'] || 2
4147

4248
# Date range for auditors to view
4349
config.auditor_unit_access_years = ENV.fetch('DF_AUDITOR_UNIT_ACCESS_YEARS', 2).to_f * 1.year
4450

45-
# Period for which to keep units
46-
config.unit_archive_after_period = ENV.fetch('DF_UNIT_ARCHIVE_PERIOD', 2).to_f * 1.year
47-
4851
config.student_import_weeks_before = ENV.fetch('DF_IMPORT_STUDENTS_WEEKS_BEFPRE', 1).to_f * 1.week
4952

5053
def self.fetch_boolean_env(name)

test/models/unit_model_test.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ def test_change_unit_code_moves_files
817817
end
818818

819819
def test_archive_unit
820+
Doubtfire::Application.config.archive_units = true
820821
unit = FactoryBot.create :unit, student_count: 1, unenrolled_student_count: 0, inactive_student_count: 0, task_count: 1, tutorials: 1, outcome_count: 0, staff_count: 0, campus_count: 1
821822

822823
td = unit.task_definitions.first
@@ -885,8 +886,17 @@ def test_archive_unit_job
885886

886887
assert_not unit.archived
887888
assert_not unit2.archived
888-
ArchiveOldUnitsJob.new.perform
889+
job = ArchiveOldUnitsJob.new
890+
job.perform
889891
unit.reload
892+
unit2.reload
893+
894+
assert_not unit.archived
895+
assert_not unit2.archived
896+
897+
Doubtfire::Application.config.archive_units = true
898+
899+
job.perform
890900

891901
assert unit.archived
892902
assert_not unit2.archived

0 commit comments

Comments
 (0)