Class: StaleTranscriptionRecoveryWorker

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

Overview

Recovers stale transcriptions that never received a webhook callback.

This worker runs every 2 hours and:

  1. Finds WebhookLog entries stuck in "pending" state for > 1 hour (awaiting callback)
  2. Checks AssemblyAI status directly for those jobs
  3. If completed, transitions to ready and processes
  4. If still processing at AssemblyAI, leaves alone
  5. If failed, marks as exception
  6. Also processes any WebhookLog entries stuck in "ready" or "retry" state

This is a safety net - webhooks should handle 99%+ of completions.
This worker catches edge cases like:

  • Webhook delivery failures
  • Network issues during webhook POST
  • Server restarts during processing
  • Worker processing failures

Schedule: Every 2 hours via sidekiq-scheduler

Constant Summary collapse

STALE_THRESHOLD =

How long to wait before considering a webhook stale (no callback received)

1.hour
MAX_AGE =

Maximum age to check (don't process ancient stuck records)

48.hours
BATCH_LIMIT =

Limit per run to avoid overwhelming the system

50

Instance Method Summary collapse

Instance Method Details

#performObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/workers/stale_transcription_recovery_worker.rb', line 36

def perform
  Rails.logger.info '[StaleTranscriptionRecoveryWorker] Starting stale transcription recovery'

  stats = { recovered: 0, failed: 0, still_processing: 0, ready_processed: 0 }

  # First, check stale pending entries (jobs that never got a callback)
  check_stale_pending_webhooks(stats)

  # Then, process any ready/retry webhook logs that need processing
  process_ready_webhook_logs(stats)

  Rails.logger.info "[StaleTranscriptionRecoveryWorker] Completed: #{stats}"
end