Class: Helios::Videos::Migration::MigrateVideosJob

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

Overview

Orchestrator job: finds all videos on the source provider and enqueues a ConvertVideoJob for each one. Processes record-by-record so long ingestions don’t block each other.

Instance Method Summary collapse

Instance Method Details

#perform(from:, to:, batch_size: nil, use_original: false) ⇒ Object

Parameters:

  • from (String)

    source provider (“cloudflare” or “mux”)

  • to (String)

    destination provider (“cloudflare” or “mux”)

  • batch_size (Integer) (defaults to: nil)

    how many to enqueue per run (default: all)

  • use_original (Boolean) (defaults to: false)

    if true, ingest from the original S3 file (via ActiveStorage) instead of downloading from the source provider. Useful if you want higher quality unprocessed source files. Requires that the original uploads still exist in your storage bucket.



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

def perform(from:, to:, batch_size: nil, use_original: false)
  video_class = Helios::Videos.video_class

  videos = video_class.where(provider: from).where.not(key: [nil, ""])
  videos = videos.limit(batch_size) if batch_size.present?

  total = videos.count
  Rails.logger.info("[helios-videos] Migration: enqueuing #{total} videos from #{from} -> #{to} (use_original: #{use_original})")

  videos.find_each do |video|
    ConvertVideoJob.perform_later(video_id: video.id, from: from, to: to, use_original: use_original)
  end

  Rails.logger.info("[helios-videos] Migration: all #{total} conversion jobs enqueued")
end