From 23bd2271fc2d8420ccbee142389b539c13c299c7 Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Fri, 31 Jan 2025 15:05:12 +1100 Subject: [PATCH] feat: auto archive of units is optional Use new environment variable to enable archive - false by default. --- app/sidekiq/archive_old_units_job.rb | 2 ++ config/application.rb | 9 ++++++--- test/models/unit_model_test.rb | 12 +++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/sidekiq/archive_old_units_job.rb b/app/sidekiq/archive_old_units_job.rb index 98c260434..7ebb68e66 100644 --- a/app/sidekiq/archive_old_units_job.rb +++ b/app/sidekiq/archive_old_units_job.rb @@ -5,6 +5,8 @@ class ArchiveOldUnitsJob include Sidekiq::Job def perform + return unless Doubtfire::Application.config.archive_units + archive_period = Doubtfire::Application.config.unit_archive_after_period archive_period = 1.year if archive_period < 1.year diff --git a/config/application.rb b/config/application.rb index c8fe73121..078bb5293 100644 --- a/config/application.rb +++ b/config/application.rb @@ -36,15 +36,18 @@ class Application < Rails::Application # Set using DF_ARCHIVE_DIR environment variable. config.archive_dir = ENV.fetch('DF_ARCHIVE_DIR', "#{config.student_work_dir}/archive") + # Allows for the archiving of units to be automated + config.archive_units = ENV['DF_ARCHIVE_UNITS'].present? && (ENV['DF_ARCHIVE_UNITS'].to_s.downcase == "true" || ENV['DF_ARCHIVE_UNITS'].to_i == 1) + + # Period for which to keep units + config.unit_archive_after_period = ENV.fetch('DF_UNIT_ARCHIVE_PERIOD', 2).to_f * 1.year + # Limit number of pdf generators to run at once config.pdfgen_max_processes = ENV['DF_MAX_PDF_GEN_PROCESSES'] || 2 # Date range for auditors to view config.auditor_unit_access_years = ENV.fetch('DF_AUDITOR_UNIT_ACCESS_YEARS', 2).to_f * 1.year - # Period for which to keep units - config.unit_archive_after_period = ENV.fetch('DF_UNIT_ARCHIVE_PERIOD', 2).to_f * 1.year - config.student_import_weeks_before = ENV.fetch('DF_IMPORT_STUDENTS_WEEKS_BEFPRE', 1).to_f * 1.week def self.fetch_boolean_env(name) diff --git a/test/models/unit_model_test.rb b/test/models/unit_model_test.rb index 81435b2b1..de605dab9 100644 --- a/test/models/unit_model_test.rb +++ b/test/models/unit_model_test.rb @@ -817,6 +817,7 @@ def test_change_unit_code_moves_files end def test_archive_unit + Doubtfire::Application.config.archive_units = true 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 td = unit.task_definitions.first @@ -885,8 +886,17 @@ def test_archive_unit_job assert_not unit.archived assert_not unit2.archived - ArchiveOldUnitsJob.new.perform + job = ArchiveOldUnitsJob.new + job.perform unit.reload + unit2.reload + + assert_not unit.archived + assert_not unit2.archived + + Doubtfire::Application.config.archive_units = true + + job.perform assert unit.archived assert_not unit2.archived