Skip to content

Instantly share code, notes, and snippets.

@nathanl
Created February 25, 2015 14:41
Show Gist options
  • Save nathanl/c1e599640901d982cd3c to your computer and use it in GitHub Desktop.
Save nathanl/c1e599640901d982cd3c to your computer and use it in GitHub Desktop.

Revisions

  1. nathanl created this gist Feb 25, 2015.
    12 changes: 12 additions & 0 deletions exponential_backoff.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Exponential backoff in Ruby
    begin
    make_request
    rescue RequestError => e
    if retries <= max_retries
    retries += 1
    sleep 2 ** retries
    retry
    else
    raise "Timeout: #{e.message}"
    end
    end