fix: Retry job if file not found (#11683)

Removed StandardError rescue blocks and added retry_on for
ResponseBuilderJob and AudioTranscriptionJob
This commit is contained in:
Pranav
2025-06-05 22:53:11 -05:00
committed by GitHub
parent 10363e77ad
commit 9b43a0f72b
4 changed files with 8 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
class Captain::Conversation::ResponseBuilderJob < ApplicationJob
MAX_MESSAGE_LENGTH = 10_000
retry_on ActiveStorage::FileNotFoundError, attempts: 3
def perform(conversation, assistant)
@conversation = conversation
@@ -12,6 +13,8 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
generate_and_process_response
end
rescue StandardError => e
raise e if e.is_a?(ActiveJob::FileNotFoundError)
handle_error(e)
ensure
Current.executed_by = nil

View File

@@ -1,13 +1,12 @@
class Messages::AudioTranscriptionJob < ApplicationJob
queue_as :low
retry_on ActiveStorage::FileNotFoundError, wait: 2.seconds, attempts: 3
def perform(attachment_id)
attachment = Attachment.find_by(id: attachment_id)
return if attachment.blank?
Messages::AudioTranscriptionService.new(attachment).perform
rescue StandardError => e
Rails.logger.error "Error in AudioTranscriptionJob: #{e.message}"
ChatwootExceptionTracker.new(e).capture_exception
end
end

View File

@@ -12,15 +12,9 @@ class Messages::AudioTranscriptionService < Llm::BaseOpenAiService
return { error: 'Transcription limit exceeded' } unless can_transcribe?
return { error: 'Message not found' } if message.blank?
begin
transcriptions = transcribe_audio
Rails.logger.info "Audio transcription successful: #{transcriptions}"
{ success: true, transcriptions: transcriptions }
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
Rails.logger.error "Audio transcription failed: #{e.message}"
{ error: "Transcription failed: #{e.message}" }
end
transcriptions = transcribe_audio
Rails.logger.info "Audio transcription successful: #{transcriptions}"
{ success: true, transcriptions: transcriptions }
end
private