From cc9521667282c270442d876f07eb2bbec11a2795 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:35:02 +0200 Subject: [PATCH] Refactor AutoArchiveProcedureWorker#perform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the loop failed, we wouldn’t update the archived attribute for procedures for which the folders were archived. That would have caused to re-run the task for procedures for which the task had already been run. --- app/workers/auto_archive_procedure_worker.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 869c8b5c6..13d14ad9f 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -2,12 +2,10 @@ class AutoArchiveProcedureWorker include Sidekiq::Worker def perform(*args) - procedures_to_archive = Procedure.not_archived.where("auto_archive_on <= ?", Date.today) + Procedure.not_archived.where("auto_archive_on <= ?", Date.today).each do |procedure| + procedure.dossiers.state_en_construction.update_all(state: :received) - procedures_to_archive.each do |p| - p.dossiers.state_en_construction.update_all(state: :received) + procedure.update_attributes!(archived: true) end - - procedures_to_archive.update_all(archived: true) end end