Files
MatchLiveTv/backend/app/jobs/stream_publisher_sync_job.rb
Emiliano Frascaro 854738b46d Stabilizza live YouTube/RTMP e fix crash rotazione mobile.
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>
2026-06-06 15:30:55 +02:00

38 lines
1.1 KiB
Ruby

# Poll MediaMTX + pipeline YouTube automatica (webhook MediaMTX non disponibile in prod).
class StreamPublisherSyncJob < ApplicationJob
queue_as :default
INTERVAL = 5.seconds
ACTIVE_STATUSES = %w[connecting live reconnecting paused].freeze
REDIS_CHAIN_KEY = "stream_publisher_sync:chain"
RUN_LOCK_KEY = "stream_publisher_sync:run_lock"
def self.ensure_chain
return if redis.get(REDIS_CHAIN_KEY)
redis.set(REDIS_CHAIN_KEY, "1", ex: INTERVAL.to_i * 4)
set(wait: INTERVAL).perform_later
end
def self.redis
@redis ||= Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
end
def perform
return unless self.class.redis.set(RUN_LOCK_KEY, "1", nx: true, ex: INTERVAL.to_i)
begin
self.class.redis.set(REDIS_CHAIN_KEY, "1", ex: INTERVAL.to_i * 4)
StreamSession
.where(status: ACTIVE_STATUSES)
.find_each do |session|
Mediamtx::PublisherSync.new(session).call
end
ensure
self.class.set(wait: INTERVAL).perform_later
self.class.redis.del(RUN_LOCK_KEY)
end
end
end