class Hubkit::Cooldowner

An object that handles Github rate throttling by setting a delay and then retrying a block

Public Class Methods

with_cooldown() { || ... } click to toggle source

Perform an action, and if Github rejects it due to rate limit, sleep and try again later @yield

# File lib/hubkit/cooldowner.rb, line 8
def self.with_cooldown
  cooldown = 1
  begin
    yield
  rescue Github::Error::Forbidden => e
    Logger.warn "Sleeping for abuse (#{cooldown} seconds)"
    sleep cooldown
    cooldown = [2 * cooldown, 10].min
    retry
  end
end