Merge pull request #9599 from demarches-simplifiees/destroy_dossier_operation_logs_with_dossier

fix: destroy dossier_operation_logs with dossier
This commit is contained in:
LeSim 2023-11-14 16:45:26 +00:00 committed by GitHub
commit 1b4010205a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,9 @@
sidekiq_enabled = ENV.has_key?('REDIS_SIDEKIQ_SENTINELS') || ENV.has_key?('REDIS_URL')
if Rails.env.production? && sidekiq_enabled
ActiveSupport.on_load(:after_initialize) do
class ActiveStorage::PurgeJob < ActiveStorage::BaseJob
self.queue_adapter = :sidekiq
end
end
end

View file

@ -0,0 +1,45 @@
namespace :after_party do
desc 'Deployment task: remove_orphan_dossier_operation_logs. You can add JOB_LIMIT env var to limit the load and manually relaunch the process if needed.'
task remove_orphan_dossier_operation_logs: :environment do
puts "Running deploy task 'remove_orphan_dossier_operation_logs'"
job_limit = ENV['JOB_LIMIT']
not_deletion_orphans = DossierOperationLog
.not_deletion
.where.missing(:dossier)
if job_limit.present?
not_deletion_orphans = not_deletion_orphans.limit(job_limit)
end
batch_size = 1_000
rake_puts "Suppression des dols avec operation != supprimer"
progress = ProgressReport.new(not_deletion_orphans.count)
not_deletion_orphans.in_batches(of: batch_size) do |b|
b.destroy_all
progress.inc(batch_size)
end
rake_puts "Supression des serialized des dols avec operation == supprimer"
deletion_orphans = DossierOperationLog.supprimer
if job_limit.present?
deletion_orphans = deletion_orphans.limit(job_limit)
end
progress = ProgressReport.new(deletion_orphans.count)
deletion_orphans.find_each(batch_size:) do |dossier_operation_log|
dossier_operation_log.serialized.purge_later
progress.inc
end
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end