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>
29 lines
737 B
Ruby
29 lines
737 B
Ruby
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
|