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>
This commit is contained in:
28
backend/app/services/youtube/api_throttle.rb
Normal file
28
backend/app/services/youtube/api_throttle.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Youtube
|
||||
# Evita tempeste di chiamate YouTube Data API (quota / userRequestsExceedRateLimit).
|
||||
class ApiThrottle
|
||||
KEY = "youtube_api:rate_limited_until"
|
||||
|
||||
class << self
|
||||
def rate_limited?
|
||||
until_ts = redis.get(KEY).to_i
|
||||
until_ts.positive? && until_ts > Time.now.to_i
|
||||
end
|
||||
|
||||
def mark_rate_limited!(seconds: 120)
|
||||
redis.set(KEY, (Time.now.to_i + seconds), ex: seconds + 30)
|
||||
end
|
||||
|
||||
def rate_limit_error?(message)
|
||||
msg = message.to_s
|
||||
msg.include?("userRequestsExceedRateLimit") || msg.include?("rate limit")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redis
|
||||
@redis ||= Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user