Refactor AutoArchiveProcedureWorker#perform

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.
This commit is contained in:
gregoirenovel 2017-05-26 19:35:02 +02:00
parent 68e734fbb5
commit cc95216672

View file

@ -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