Class: Hubkit::Cooldowner

Inherits:
Object
  • Object
show all
Defined in:
lib/hubkit/cooldowner.rb

Overview

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

Class Method Summary collapse

Class Method Details

.with_cooldown { ... } ⇒ Object

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

Yields:


8
9
10
11
12
13
14
15
16
17
18
# 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