demarches-normaliennes/app/workers/auto_archive_procedure_worker.rb
gregoirenovel cc95216672 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.
2017-06-08 15:06:01 +02:00

11 lines
316 B
Ruby

class AutoArchiveProcedureWorker
include Sidekiq::Worker
def perform(*args)
Procedure.not_archived.where("auto_archive_on <= ?", Date.today).each do |procedure|
procedure.dossiers.state_en_construction.update_all(state: :received)
procedure.update_attributes!(archived: true)
end
end
end