knifeswitch 1.0.0 → 1.1.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fce0afa125f824b748eae256d752487d221343c5ca839613f2fe8547288f893
4
- data.tar.gz: 8f6bfb756e1dd154449178873c459cdba208b70a3c8290329cb1d29f7da44e46
3
+ metadata.gz: c21ca91eae9b7d22ebef28c43b90429e6e1c5e10501fd39e54eefffec2f2ef45
4
+ data.tar.gz: 5faa4bc86e93ad8dbff72095b2f4da97adeb8e54ebc9d0ec8191b4db0c7999ea
5
5
  SHA512:
6
- metadata.gz: c87ebd2d6d76d1ed34e83c7fb582cd6ada8e1c7cfd5fea4fb0f70ba3a0d856f2c1d3caf434ed7a59251d7ae3d898bd7b8b0b59fed9f6845fc7a060c72119b3cf
7
- data.tar.gz: 3b8cc2c3b87092340af8530003dc754d3fdf410cad2a26944a4d5575cb1bebe2b9385a25a97892ddfedb2cc49484080868444e10d782f21c9049b32d7314c6b8
6
+ metadata.gz: 294756a35f27839e007c34496e550d88e95979f0252f1532536b06851de52c87f7f0fcf8f51e384976189a728a1c6d91b1f9dcb1fea918955ff022a1d16485c0
7
+ data.tar.gz: 94bc6838ab85d95ca0bc42a5ca131e487d63dbeaa67f2c5075b9d482418b08ea8a5e363b38e4b5b169d8ee080f33b827c0017754949c20de2acd0928862f13fc
@@ -22,6 +22,7 @@ module Knifeswitch
22
22
  #
23
23
  class Circuit
24
24
  attr_reader :namespace, :exceptions, :error_threshold, :error_timeout
25
+ attr_accessor :callback
25
26
 
26
27
  # Options:
27
28
  #
@@ -33,12 +34,14 @@ module Knifeswitch
33
34
  namespace: 'default',
34
35
  exceptions: [Timeout::Error],
35
36
  error_threshold: 10,
36
- error_timeout: 60
37
+ error_timeout: 60,
38
+ callback: nil
37
39
  )
38
40
  @namespace = namespace
39
41
  @exceptions = exceptions
40
42
  @error_threshold = error_threshold
41
43
  @error_timeout = error_timeout
44
+ @callback = callback
42
45
  end
43
46
 
44
47
  # Call this with a block to execute the contents of the block under
@@ -46,7 +49,10 @@ module Knifeswitch
46
49
  #
47
50
  # Raises Knifeswitch::CircuitOpen when called while the circuit is open.
48
51
  def run
49
- raise CircuitOpen if open?
52
+ if open?
53
+ callback.try(:call, CircuitOpen.new)
54
+ raise CircuitOpen
55
+ end
50
56
 
51
57
  result = yield
52
58
  reset_counter!
@@ -54,6 +60,7 @@ module Knifeswitch
54
60
  rescue Exception => error
55
61
  if exceptions.any? { |watched| error.is_a?(watched) }
56
62
  increment_counter!
63
+ callback.try(:call, error)
57
64
  else
58
65
  reset_counter!
59
66
  end
@@ -1,3 +1,3 @@
1
1
  module Knifeswitch
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knifeswitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie