Skip to content

Commit

Permalink
feat: auto archive of units is optional
Browse files Browse the repository at this point in the history
Use new environment variable to enable archive - false by default.
  • Loading branch information
macite committed Jan 31, 2025
1 parent 9b2cf03 commit 23bd227
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/sidekiq/archive_old_units_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion test/models/unit_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23bd227

Please sign in to comment.