demarches-normaliennes/app/jobs/cron/auto_archive_procedure_job.rb

29 lines
761 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Cron::AutoArchiveProcedureJob < Cron::CronJob
self.schedule_expression = "every 1 minute"
2017-10-03 16:19:25 +02:00
def perform(*args)
procedures_to_close.each do |procedure|
# A buggy procedure should NEVER prevent the closing of another procedure
# we therefore exceptionally add a `begin resue` block.
begin
procedure
.dossiers
.state_en_construction
.find_each(&:passer_automatiquement_en_instruction!)
procedure.close!
rescue StandardError => e
2021-01-28 14:49:22 +01:00
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
end
end
end
def procedures_to_close
Procedure
.publiees
.where("auto_archive_on <= ?", Time.zone.today)
end
end