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

26 lines
712 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Cron::AutoArchiveProcedureJob < Cron::CronJob
self.schedule_expression = "every 1 minute"
queue_as :critical
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.close!
AutoArchiveProcedureDossiersJob.perform_later(procedure)
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