Class: CallRecordTranscriptionWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/call_record_transcription_worker.rb

Overview

Background worker for transcribing call recordings using AssemblyAI.
Processes individual call records and generates transcripts with speaker diarization.

Examples:

Queue a single call record

CallRecordTranscriptionWorker.perform_async(call_record_id: 123)

Force retranscription

CallRecordTranscriptionWorker.perform_async(call_record_id: 123, force: true)

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/workers/call_record_transcription_worker.rb', line 17

def perform(options = {})
  options = options.symbolize_keys
  call_record_id = options[:call_record_id]

  unless call_record_id
    Rails.logger.error '[CallRecordTranscriptionWorker] Missing call_record_id'
    return
  end

  call_record = CallRecord.find_by(id: call_record_id)
  unless call_record
    Rails.logger.error "[CallRecordTranscriptionWorker] CallRecord #{call_record_id} not found"
    return
  end

  Rails.logger.info "[CallRecordTranscriptionWorker] Processing CallRecord #{call_record_id}"

  # Run the transcription service
  service = CallRecordProcessing::TranscriptionService.new(call_record, force: options[:force])
  result = service.transcribe

  case result[:status]
  when :success
    Rails.logger.info "[CallRecordTranscriptionWorker] Success for CallRecord #{call_record_id}: #{result[:word_count]} words"

    # Queue AI summary generation
    CallRecordSummaryWorker.perform_async(call_record_id: call_record_id)

    # Queue embedding generation
    EmbeddingWorker.perform_async('CallRecord', call_record_id)

  when :skipped
    Rails.logger.info "[CallRecordTranscriptionWorker] Skipped CallRecord #{call_record_id}: #{result[:reason]}"

  when :error
    # Service caught the exception and returned error result (swallowed).
    # Must report explicitly since no exception will reach AppSignal.
    error_message = "[CallRecordTranscriptionWorker] Error for CallRecord #{call_record_id}: #{result[:reason]} - #{result[:message]}"
    Rails.logger.error error_message
    ErrorReporting.error(
      StandardError.new(error_message),
      source: :background,
      call_record_id: call_record_id,
      reason: result[:reason]
    )
  end
  # Note: Unexpected exceptions will propagate up and AppSignal's Sidekiq
  # integration will catch them automatically - no need for explicit reporting.
end