Class: CloudflareVideoMonitorWorker
- Inherits:
-
Object
- Object
- CloudflareVideoMonitorWorker
- Includes:
- Sidekiq::Worker, Workers::StatusBroadcastable
- Defined in:
- app/workers/cloudflare_video_monitor_worker.rb
Overview
Worker that monitors Cloudflare video processing and automatically creates downloads
when the video is ready
Constant Summary collapse
- MAX_WAIT_TIME =
Maximum time to wait for video processing (60 minutes)
60.minutes
- CHECK_INTERVAL =
Check status every 30 seconds
30.seconds
- MAX_CHECKS =
Maximum number of checks
(MAX_WAIT_TIME / CHECK_INTERVAL).to_i
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(video_id, options = {}) ⇒ Object
16 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 66 67 68 |
# File 'app/workers/cloudflare_video_monitor_worker.rb', line 16 def perform(video_id, = {}) @video = Video.find(video_id) @options = .symbolize_keys @redirect_path = @options[:redirect_path] || "#{CRM_URL}/videos/#{@video.id}" @start_time = Time.current return unless @video.is_cloudflare? # Set initial status total(100) at(0, 'Starting Cloudflare video monitoring...') begin # Step 1: Wait for video to be ready (0-50%) wait_for_video_ready # Step 2: Create default video download (50%) at(50, 'Creating default video download...') create_download('default') # Step 3: Wait for default video download to be ready (50-70%) wait_for_download_ready('default') # Step 4: Create audio download (70%) at(70, 'Creating audio download...') create_download('audio') # Step 5: Wait for audio download to be ready (70-90%) wait_for_download_ready('audio') # Step 6: Final refresh to confirm everything is ready (90-100%) at(90, 'Performing final status refresh...') @video.refresh_cloudflare_data at(95, 'All downloads verified!') # Complete store status: 'completed' at(100, 'Video processing and downloads completed successfully!') store redirect_to: @redirect_path rescue StandardError => e = e. Rails.logger.error "Cloudflare video monitoring failed for video #{@video.id}: #{}" Rails.logger.error e.backtrace.join("\n") # Store failure status and error message store status: 'failed' store error_message: store redirect_to: @redirect_path # Report to AppSignal ErrorReporting.error(e, source: :background, video_id: @video.id) end end |