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

19 lines
634 B
Ruby
Raw Normal View History

class Cron::OperationsSignatureJob < Cron::CronJob
self.schedule_expression = "every day at 6 am"
2019-06-04 10:37:05 +02:00
def perform(*args)
2024-04-18 11:18:53 +02:00
start_date = DossierOperationLog.where(bill_signature: nil).order(:executed_at).pick(:executed_at).beginning_of_day
2019-06-04 10:37:05 +02:00
last_midnight = Time.zone.today.beginning_of_day
2024-04-18 11:18:53 +02:00
while start_date < last_midnight
operations = DossierOperationLog
2024-04-18 11:19:51 +02:00
.select(:id, :digest)
2024-04-18 11:18:53 +02:00
.where(executed_at: start_date...start_date.tomorrow, bill_signature: nil)
BillSignatureService.sign_operations(operations, start_date) if operations.present?
start_date = start_date.tomorrow
2019-06-04 10:37:05 +02:00
end
end
end