2020-11-13 14:34:53 +01:00
|
|
|
class Cron::AutoArchiveProcedureJob < Cron::CronJob
|
2020-04-01 15:26:46 +02:00
|
|
|
self.schedule_expression = "every 1 minute"
|
2017-10-03 16:19:25 +02:00
|
|
|
|
2017-03-15 12:40:59 +01:00
|
|
|
def perform(*args)
|
2021-01-05 10:03:35 +01:00
|
|
|
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!)
|
2017-03-15 12:40:59 +01:00
|
|
|
|
2021-01-05 10:03:35 +01:00
|
|
|
procedure.close!
|
|
|
|
rescue StandardError => e
|
|
|
|
Raven.capture_exception(e, extra: { procedure_id: procedure.id })
|
|
|
|
end
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|
|
|
|
end
|
2021-01-05 10:03:35 +01:00
|
|
|
|
|
|
|
def procedures_to_close
|
|
|
|
Procedure
|
|
|
|
.publiees
|
|
|
|
.where("auto_archive_on <= ?", Time.zone.today)
|
|
|
|
end
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|