Class: YouTubeSyncWorker
- Inherits:
-
Object
- Object
- YouTubeSyncWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/youtube_sync_worker.rb
Overview
Synchronizes YouTube metadata for all videos that have a youtube_id.
Can be triggered manually from the CRM or run on a schedule.
Uses batched API calls (50 videos per request) to stay within quota.
Instance Method Summary collapse
Instance Method Details
#perform(video_id = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/workers/youtube_sync_worker.rb', line 14 def perform(video_id = nil) service = YouTube::SyncService.new if video_id Rails.logger.info("[YouTubeSyncWorker] Syncing single video #{video_id}") service.sync_video(video_id) else Rails.logger.info('[YouTubeSyncWorker] Syncing all videos with youtube_id') stats = service.sync_existing_videos Rails.logger.info("[YouTubeSyncWorker] Done: #{stats.inspect}") end rescue YouTube::OauthService::TokenRefreshError => e Rails.logger.error("[YouTubeSyncWorker] OAuth error: #{e.}") rescue YouTube::ApiClient::ApiError => e Rails.logger.error("[YouTubeSyncWorker] API error: #{e.}") end |