Skip to content

mfine/sf6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Circuit Breaker / Rate Limiter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages