circuit_breaker-ruby 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODI4Yjg5MTZiZTQxMDUyOWM2N2MzNWI2YWRlYjQ1ZmE4N2IyMDIwYw==
4
+ N2RmNmY0NDYzZWUwZjBjODdhMTU1MjQzNDJiYjg4NGNmMGUzOWE2Yw==
5
5
  data.tar.gz: !binary |-
6
- YjM1NzZhN2FlYThmMTlmZTI2NGFiNDQ4Y2ZkOGIzMDQwYzJjOTQwYg==
6
+ MDA3MGE3MzM5YTgxYjJjZGIzMjdlNTRjOTQyNThlYmNlZGVhOThlMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGUxMTZhMGQ5NmFiZjBjMDE2YmQ0Mjk4MWUwYjk4YjE0NWUzY2JmNGMzOTQ1
10
- ZjYxNmZhYjA4MmRiM2M3ZmI4OTM4NGJiNTdhYjM1YWM2MzAxYTQwOTc3NDU5
11
- NTJmYzg2YjgyOGY1N2VhZDlhNmY2YTZlMzQxZmM3MmUyMmNkNDY=
9
+ YjEzNzJhODgzNjNjOTY4ZDBiOGUxNTM2ODUxYjJlNzI3YzNmNjY4NzQ3YTEw
10
+ ZDRmYzYxMmZmNzUxNjA4NDZiOWFlYzI2M2U4MDJlYmRjMTJlYjZiYzY0ZjA1
11
+ MWZmODY5MTI3ZTExMGZiZGVmYWIzZTQxZTUxODJmNjFmMzhlYmI=
12
12
  data.tar.gz: !binary |-
13
- MWIxZWFkZTAxZmMyMWU2N2ZjOTNlYmE3M2VmMzc3YzI3OTFhNmZkMjIzNzM5
14
- ZDVhNjUxZDc3YjYwNjllZjBiNDU0M2E1NzQ3NTAyNTU3ZWJiMDRmMzkwNjlm
15
- ZWYwNGUxYTM0Y2M0NDIxMjZiZjNmOTk3NTc0NTJiZmFkOTY2YWU=
13
+ ZTJhOGZjYTQ0ZGYxNzA1MTNkYzI3NTgzYzRjZmM2ZTI2NDdkYWFhZmZjZWFm
14
+ ZjgwNThkZjUwOTdiOGRlODc2ZDVmOTI3N2RhNDk0NWQ5NzUyZDk0MWU0NjQ0
15
+ NzQ4NDQxZDU5MGRkODVjYmFhNTkyODVjMWY3YjE0MDNlZjc5YjY=
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  ## Circuit Breaker
2
+ [![Gem Version](https://img.shields.io/gem/v/circuit_breaker-ruby.svg?style=flat)](http://rubygems.org/gems/circuit_breaker-ruby)
3
+ [![Build Status](https://travis-ci.org/scripbox/circuit_breaker-ruby.svg?style=flat&branch=master)](https://travis-ci.org/scripbox/circuit_breaker-ruby)
4
+
2
5
  A circuit breaker which terminates a connection or block of code from executing when it reaches the failure threshold and a percentage. Also it gets reset when a connection succeeds. It also keeps monitoring if connections are working again by checking if it has attained a time to retry.
3
6
 
4
7
  ## Installation
@@ -3,7 +3,7 @@ require './lib/circuit_breaker-ruby/version'
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'circuit_breaker-ruby'
5
5
  gem.version = CircuitBreaker::VERSION
6
- gem.date = '2016-10-09'
6
+ gem.date = '2016-09-09'
7
7
  gem.summary = 'Circuit breaker for ruby'
8
8
  gem.description = 'Self-resetting breaker retries the protected call after a suitable interval, and it also resets when the call succeeds.'
9
9
  gem.author = 'Scripbox'
@@ -5,6 +5,13 @@ module CircuitBreaker
5
5
  INVOCATION_TIMEOUT = 10
6
6
  RETRY_TIMEOUT = 60
7
7
 
8
+ UPDATABLE = [
9
+ :invocation_timeout,
10
+ :failure_threshold,
11
+ :failure_threshold_percentage,
12
+ :retry_timeout
13
+ ]
14
+
8
15
  attr_accessor :invocation_timeout, :failure_threshold, :failure_threshold_percentage, :retry_timeout
9
16
 
10
17
  def initialize
@@ -22,7 +22,15 @@ module CircuitBreaker
22
22
  CircuitBreaker.config
23
23
  end
24
24
 
25
- def protect(&block)
25
+ def update_config!(options)
26
+ (CircuitBreaker::Config::UPDATABLE & options.keys).each do |variable|
27
+ instance_variable_set("@#{variable}", options[variable])
28
+ end
29
+ end
30
+
31
+ def protect(options = {}, &block)
32
+ update_config!(options)
33
+
26
34
  case prev_state = state
27
35
  when States::CLOSED, States::HALF_OPEN
28
36
  connect(&block).tap { update_total_count(prev_state) }
@@ -1,3 +1,3 @@
1
1
  module CircuitBreaker
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -47,4 +47,12 @@ describe CircuitBreaker::Shield do
47
47
  raise_error(CircuitBreaker::Open)
48
48
  )
49
49
  end
50
+
51
+ context '#protect' do
52
+ it 'update invocation_timeout in config' do
53
+ circuit_breaker_shield.protect(invocation_timeout: 20) {}
54
+
55
+ expect(circuit_breaker_shield.invocation_timeout).to be(20)
56
+ end
57
+ end
50
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuit_breaker-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scripbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-09 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec