Pipeline YouTube con relay, overlay e publisher sync lato backend; fix GL pauseGlDuringRotation su Android per evitare crash in rotazione durante lo streaming Flutter. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.7 KiB
Ruby
55 lines
1.7 KiB
Ruby
class YoutubeBroadcastActivateJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
MAX_ATTEMPTS = 30
|
|
RETRY_WAIT = 15.seconds
|
|
RATE_LIMIT_WAIT = 90.seconds
|
|
LIVE_STATUSES = %w[live connecting reconnecting paused].freeze
|
|
|
|
def perform(session_id, attempt = 1)
|
|
session = StreamSession.find_by(id: session_id)
|
|
return unless session&.platform == "youtube"
|
|
return if session.terminal?
|
|
return if session.youtube_broadcast_id.blank?
|
|
return unless LIVE_STATUSES.include?(session.status)
|
|
return unless Youtube::LivePipeline.broadcast_ready?(session)
|
|
|
|
unless Streams::YoutubeRelay.running?(session.id)
|
|
Streams::YoutubeRelay.ensure_publishing!(session)
|
|
return reschedule(session_id, attempt + 1) if attempt < MAX_ATTEMPTS
|
|
|
|
return
|
|
end
|
|
|
|
result = Youtube::BroadcastService.new(session.match.team).activate_broadcast!(session.youtube_broadcast_id)
|
|
Rails.logger.info("[YoutubeBroadcastActivate] session=#{session.id} attempt=#{attempt} result=#{result}")
|
|
|
|
return if result == :live || result == :transitioned
|
|
|
|
if result == :rate_limited
|
|
reschedule(session_id, attempt, wait: RATE_LIMIT_WAIT)
|
|
return
|
|
end
|
|
|
|
if result == :broadcast_ended
|
|
Youtube::SetupBroadcast.recreate!(session.reload)
|
|
Youtube::LivePipeline.schedule!(session.reload, force: true)
|
|
return
|
|
end
|
|
|
|
if result == :waiting_ingest && (attempt % 4).zero?
|
|
Streams::YoutubeRelay.ensure_publishing!(session)
|
|
end
|
|
|
|
return if attempt >= MAX_ATTEMPTS
|
|
|
|
reschedule(session_id, attempt + 1)
|
|
end
|
|
|
|
private
|
|
|
|
def reschedule(session_id, attempt, wait: RETRY_WAIT)
|
|
self.class.set(wait: wait).perform_later(session_id, attempt)
|
|
end
|
|
end
|