Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Circuit Breaker / Rate Limiter
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
Gemfile
Gemfile.lock
README.md
sf6.gemspec

README.md

SF6

SF6

Simple circuit breaking, rate limiting.

Using

require "sf6"

class Numeric
  def seconds
    self
  end

  def minutes
    seconds * 60
  end
end

# rate limit to under 3 every minute
10.times do
  puts "limiter trying..."
  begin
    SF6::Limiter.check("first", 3, 1.minutes) do
      puts "limit success"
    end
  rescue SF6::Unavailable
    puts "limiter unavailable"
  rescue => e
    puts "limiter other"
    puts e
  end
  puts
  sleep 1
end

# circuit break to under 3 failures every minute
10.times do
  puts "breaker trying..."
  begin
    SF6::Breaker.check("first", 3, 1.minutes) do
      puts "breaker success"
      raise("zomg")
    end
  rescue SF6::Unavailable
    puts "breaker unavailable"
  rescue => e
    puts "breaker other"
    puts e
  end
  puts
  sleep 1
end
Something went wrong with that request. Please try again.