class AnalyzeAudioJob < ApplicationJob
  queue_as :default

  def perform(video)
    response = BrayniacAI::AudioRecognition.create! AudioAnalysis.new(video)
    
    video.update!({
      audio_analysis_uid: response.job_id,
      audio_analysis_started_at: Time.zone.now,
      audio_analysis_status: :pending,
    })

  rescue StandardError => e
    video.audio_analysis_failure!
    Rails.logger.error("Failed to perform audio analysis for video(##{video.id})\n" + e.message)
  end
end
