demarches-normaliennes/app/tasks/maintenance/spread_dossier_deletion_task.rb

25 lines
796 B
Ruby

# frozen_string_literal: true
module Maintenance
class SpreadDossierDeletionTask < MaintenanceTasks::Task
ERROR_OCCURED_AT = Date.new(2024, 2, 14)
ERROR_OCCURED_RANGE = ERROR_OCCURED_AT.at_midnight..(ERROR_OCCURED_AT + 1.day)
SPREAD_DURATION_IN_DAYS = 150
def collection
Dossier.where(termine_close_to_expiration_notice_sent_at: ERROR_OCCURED_RANGE)
.in_batches
end
def process(element)
element.update_all(termine_close_to_expiration_notice_sent_at: ERROR_OCCURED_AT + random_date_spread.days)
end
# since we do not keep track of current batch idx,
# delay termine_close_to_expiration_notice_sent_at using random approach
# should be good enough
def random_date_spread
rand(1..SPREAD_DURATION_IN_DAYS)
end
end
end