Class: VideoPosterExtractionWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/video_poster_extraction_worker.rb

Overview

Sidekiq worker: video poster extraction.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(video_id, timestamp_seconds = nil, redirect_to = nil, target_attribute = 'poster_image_id') ⇒ Object

target_attribute is a positional string so the JSON-serialized Sidekiq
payload stays trivially serializable. Defaults preserve the original
poster_image_id flow for callers that don't pass it.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/workers/video_poster_extraction_worker.rb', line 13

def perform(video_id, timestamp_seconds = nil, redirect_to = nil, target_attribute = 'poster_image_id')
  video = Video.find(video_id)

  timestamp_seconds = 5.0 if timestamp_seconds.nil? || timestamp_seconds < 0

  total(100)
  at(0, "Starting frame extraction for video #{video.title}")
  store redirect_to: redirect_to if redirect_to.present?

  at(25, 'Extracting frame using optimized service...')

  service = VideoPosterExtractionService.new(video, timestamp_seconds, target_attribute: target_attribute.to_sym)
  service.extract_poster

  at(100, 'Frame extraction completed successfully!')
rescue VideoPosterExtractionService::ExtractionError => e
  store error_message: e.message
  raise
end