module Recordings
  class ExpiryWarningJob
    include Sidekiq::Job
    sidekiq_options retry: 1, queue: "default"

    def perform
      Recording.ready
               .where(expiry_warning_sent_at: nil)
               .where.not(expires_at: nil)
               .where(expires_at: ..7.days.from_now)
               .find_each do |recording|
        Recordings::NotifyExpiring.new(recording).call
      rescue StandardError => e
        Rails.logger.warn("[Recordings::ExpiryWarningJob] #{recording.id}: #{e.message}")
      end
    end
  end
end
