class Srcom::RateLimiter

Overview

This keeps track of the requests being made the speedrun.com API, making sure that the rate limit isn't exceeded. To account for slight inaccuracies an additional #backoff_time (which defaults to 1 second) can be specified. This is added to the time that is needed at minimum to be allowed another request.

Defined in:

srcr/rate_limiter.cr

Constant Summary

Log = Srcom::Log.for("rate_limit")

Constructors

Instance Method Summary

Constructor Detail

def self.new(backoff_time : Float64 = 1) #

Makes a new RateLimiter with the given backoff_time in seconds.


[View source]

Instance Method Detail

def backoff_time : Float64 #

[View source]
def backoff_time=(backoff_time : Float64) #

[View source]
def check_rate_limit(endpoint : String) #

Ensures the rate limit is not currently being hit.

NOTE endpoint is purely for logging purposes.


[View source]
def global_rate_limit_exceeded #

Waits until the oldest request occurred 60 seconds ago + twice the usual backoff time.

NOTE This only gets called if this RateLimiter fails, the rate limit gets exceeded, and speedrun.com returns error code 420.


[View source]