Class: Helios::Videos::Migration::CheckIngestionJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/helios/videos/migration/check_ingestion_job.rb

Overview

Polls the destination provider (Cloudflare) to check if a migrated video has finished processing. Once ready, flips the provider column.

Only needed for Cloudflare as a destination — Mux returns playback IDs immediately so no polling is required.

Constant Summary collapse

MAX_ATTEMPTS =

~30 minutes with 30s intervals

60

Instance Method Summary collapse

Instance Method Details

#perform(video_id:, to:, attempt: 1) ⇒ Object

Parameters:

  • video_id (Integer)
  • to (String)

    destination provider

  • attempt (Integer) (defaults to: 1)

    current attempt number



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/jobs/helios/videos/migration/check_ingestion_job.rb', line 17

def perform(video_id:, to:, attempt: 1)
  video = Helios::Videos.video_class.find(video_id)
  dest_processor = Helios::Videos.processor_for(to.to_sym)

  if dest_processor.ready?(video)
    video.update!(provider: to)
    Rails.logger.info("[helios-videos] Migration: video #{video_id} is ready on #{to}, provider flipped (attempt #{attempt})")

    dest_processor.download_thumbnail!(video)
  elsif attempt >= MAX_ATTEMPTS
    Rails.logger.error("[helios-videos] Migration: video #{video_id} still not ready after #{MAX_ATTEMPTS} attempts, giving up")
  else
    Rails.logger.info("[helios-videos] Migration: video #{video_id} not yet ready on #{to}, retrying (attempt #{attempt})")
    CheckIngestionJob.set(wait: 30.seconds).perform_later(
      video_id: video_id,
      to: to,
      attempt: attempt + 1
    )
  end
end