• Stars
    star
    403
  • Rank 107,140 (Top 3 %)
  • Language
    Ruby
  • Created over 15 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of Michael Nygard's Circuit Breaker pattern in Ruby

circuit_breaker

DESCRIPTION:

CircuitBreaker is a relatively simple Ruby mixin that will wrap a call to a given service in a circuit breaker pattern.

The circuit starts off "closed" meaning that all calls will go through. However, consecutive failures are recorded and after a threshold is reached, the circuit will "trip", setting the circuit into an "open" state.

In an "open" state, every call to the service will fail by raising CircuitBrokenException.

The circuit will remain in an "open" state until the failure timeout has elapsed.

After the failure_timeout has elapsed, the circuit will go into a "half open" state and the call will go through. A failure will immediately pop the circuit open again, and a success will close the circuit and reset the failure count.

For services that can take an unmanagable amount of time to respond an invocation timeout threshold is provided. If the service fails to return before the invocation_timeout duration has passed, the circuit will "trip", setting the circuit into an "open" state.

require 'circuit_breaker'
class TestService
  include CircuitBreaker

  def call_remote_service() ...

  circuit_method :call_remote_service

  # Optional
  circuit_handler do |handler|
    handler.logger = Logger.new(STDOUT)
    handler.failure_threshold = 5
    handler.failure_timeout = 5
    handler.invocation_timeout = 10
    handler.excluded_exceptions = [NotConsideredFailureException]
  end

  # Optional
  circuit_handler_class MyCustomCircuitHandler
end

FEATURES/PROBLEMS:

  • Can run out of the box with minimal dependencies and a couple of lines of code.
  • Easy to extend: add your own circuit breakers or states or extend the existing ones.
  • Does not currently handle static class methods.

SYNOPSIS:

An implementation of Michael Nygard's Circuit Breaker pattern.

REQUIREMENTS:

circuit_breaker has a dependency on AASM @ http://github.com/rubyist/aasm/tree/master

INSTALL:

  • gem install circuit_breaker

LICENSE:

Copyright (c) 2016, Will Sargent All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

docker-cheat-sheet

Docker Cheat Sheet
21,630
star
2

docker-devenv

Docker based development environment
130
star
3

toodledo

Ruby library (including command line client) for interacting with toodledo.com USES DEPRECATED V1 API
Ruby
59
star
4

play20-rememberme

Example Play authentication with remember me cookies.
Scala
32
star
5

slf4j-benchmark

Microbenchmark of SLF4J / Logback using JMH
Scala
17
star
6

play-ws-with-letsencrypt

Example Play WS configuration using Letsencrypt as a Root CA.
Scala
15
star
7

securityfixer

Experimental Java agent to stomp on things.
Java
15
star
8

shade-with-sbt-assembly

SBT project showing shading a library with SBT assembly
Scala
12
star
9

paranoid-java-serialization

Adds a guard to disable ObjectInputStream.readObject
Java
11
star
10

nojndi

Disables JNDI lookup globally using Java agent instrumentation, mitigation for Log4Shell attacks.
Java
9
star
11

sbt-with-jdk-13-docker-logging-example

This is an sbt Scala hello world app example that shows compiling with JDK 13, packaging in docker and as an app.
Scala
9
star
12

sbt-rss

Simple SBT plugin showing RSS integration
Scala
9
star
13

play-jdk13-alpine-slim

Minimal Play 2.8.0 running on openjdk13/alpine-slim docker image.
Scala
7
star
14

play-akka-command-app

A small application that shows Play and Akka using the Command pattern.
Scala
7
star
15

evernote-import

Some evernote import scripts, written in Ruby.
Ruby
6
star
16

sandboxexperiment

Demonstrates a self-protecting sandbox using SecurityManager
Scala
6
star
17

conditional-tracing

A Java project that shows dynamic creation of spans using conditions.
Java
6
star
18

scala-failsafe

Scala Wrapper for https://github.com/jhalterman/failsafe
Scala
4
star
19

play-ws-using-http-cache-example

Example of Play WS using an HTTP cache
Scala
3
star
20

prograde-example

Example sample prograde project
Scala
3
star
21

scala3-inspections

Scala
3
star
22

bcrypt-benchmark

JMH bcrypt project for checking how large your work factor should be.
Java
3
star
23

slim-play-with-custom-logger

Simplest Possible Play
Scala
3
star
24

java-rfc7525

Configuration of JSSE SSLEngine to be RFC7525 compliant
Java
3
star
25

docker-scala-sbt

Preconfigured SBT / Scala / Java Development Environment with Docker
Shell
3
star
26

jedit-docker-mode

A docker mode for jEdit
2
star
27

filewatching-java-project

Java project that watches for changes in keystores/truststores
Java
2
star
28

memalloctest

HTML
2
star
29

play-scala-service-example

Play Service with Macwire / Endpoints / Akka Typed
Scala
2
star
30

jce-aes-cipher-poc

Java
2
star
31

scalafx-ammonite

A very short demo of how to run scalafx GUI applications using Ammonite scripting.
Scala
2
star
32

vagrant-tailscale-example

Ansible playbooks to create vagrant boxes configured with Tailscale and 1Password
Shell
1
star
33

sbt-release-with-javasubproject

Get sbt-release working with java subproject
Scala
1
star
34

bsh-module

Beanshell module for ATG
Java
1
star
35

shadowConverter

Shadow XML converter for the Palm Pilot to Ecco Pro (very unlikely you'll use this)
Java
1
star
36

play-jetbrains

Scala
1
star
37

eccoapi

Ecco Pro API in Perl (uses DDE)
Perl
1
star
38

tlspretense-docker

Shell
1
star
39

play-cucumber

Example Play Cucumber web application
Scala
1
star
40

play-scala-with-jmx

Play Application using JMX to show logs and components
CSS
1
star