class

Srcom::RateLimiter

Inherits Reference / Object

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.

Constants

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

Constructors

new(backoff_time : Float64 = 1)

Makes a new RateLimiter with the given backoff_time in seconds.

Source

Instance methods

backoff_time
Source
backoff_time=(backoff_time : Float64)
Source
check_rate_limit(endpoint : String)

Ensures the rate limit is not currently being hit.

NOTE: endpoint is purely for logging purposes.

Source
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.

Source