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:
parent
68e734fbb5
commit
cc95216672
1 changed files with 3 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue