sc4ry 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ae3dacd25cc9d2d453bdb6a8e6bd78fd27e0b366112d43bfdff4572a6fd31ae
4
- data.tar.gz: 0bf6f07d3a1a32767218c136c84c299fc9583e73e2b37a4f3631dcd6ff660c79
3
+ metadata.gz: f9a3fb1c8109f854824988f024f067a17a4911af9a50a6fe2b3810b48ee04a3e
4
+ data.tar.gz: b76605ccc355dcba888eae092ed01fd554a1d74de80bbc576e5942ff1f8e6d41
5
5
  SHA512:
6
- metadata.gz: b8c2fbf08267a79b0b2157f9164905c576663e662c1259e1a1c6b1f8227fb2cc66a022f9f4ff55adf3d785ce41b71705ff8df78b807243cce14cf37491e8ac07
7
- data.tar.gz: 6cf5d585617227d28d9c7669f4f1152ad6949b6ecd167a2ca12c1972c6003d4bd91dd2d72ede4c7241385b29c2e306af580e6f7ad041b64828393bf7c9ef0d13
6
+ metadata.gz: 466cbe185262a5b854b70812ce7d37f8e2032fb3f85346f3d3c42dfe202757dcc1f1b7634b91327d73bb8e795c11093c75867de002011b0e6832c28221396eea
7
+ data.tar.gz: f93131f1c494030d16377fec8fb8380755265a44a497365e8246e9e9a80c43cd3d921ac2b327cf17e74df6c665541a9a1c610a6916b20d9f3ae2b30391760a08
data/README.md CHANGED
@@ -39,16 +39,24 @@ pp Sc4ry::Circuits.list
39
39
  # display default config, must be override with a nested hash by calling default_config= method
40
40
  pp Sc4ry::Circuits.default_config
41
41
 
42
+
43
+ # Config an alternate logger
44
+ Sc4ry::Logger.register name: :perso, instance: ::Logger.new('/tmp/logfile.log')
45
+ Sc4ry::Logger::current = :perso
46
+
47
+
42
48
  # default values, circuit is half open before one of the max count is reached
43
49
 
44
50
  # {:max_failure_count=>5, => maximum failure before opening circuit
45
51
  # :timeout_value=>20, => timeout value, if :timeout => true
46
- # :timeout=>false, => activate internal timeout
52
+ # :timeout=>false, => (de)activate internal timeout
47
53
  # :max_timeout_count=>5, => maximum timeout try before opening circuit
48
54
  # :max_time=>10, => maximum time for a circuit run
49
55
  # :max_overtime_count=>3, => maximum count of overtime before opening circuit
50
56
  # :check_delay=>30, => delay after opening, before trying again to closed circuit or after an other check
51
57
  # :notifiers=>[], => active notifier, must be :symbol in [:prometheus, :mattermost]
58
+ # :forward_unknown_exceptions => true, => (de)activate forwarding of unknown exceptions, just log in DEBUG if false
59
+ # :raise_on_opening => false, => (de)activate raise specific Sc4ry exceptions ( CircuitBreaked ) if circuit opening
52
60
  # :exceptions=>[StandardError, RuntimeError]} => list of selected Exceptions considered for failure, others are SKIPPED.
53
61
 
54
62
  # display configuration for a specific circuit
@@ -11,6 +11,8 @@ module Sc4ry
11
11
  :max_overtime_count => 3,
12
12
  :check_delay => 30,
13
13
  :notifiers => [],
14
+ :forward_unknown_exceptions => true,
15
+ :raise_on_opening => false,
14
16
  :exceptions => [StandardError, RuntimeError]
15
17
  }
16
18
 
@@ -86,7 +88,10 @@ module Sc4ry
86
88
  [:closed,:half_open,:open].each do |status|
87
89
  data[:status][:general] = status if worst_status.include? status
88
90
  end
89
- Sc4ry::Helpers.notify circuit: options[:circuit], config: data if save != data[:status][:general]
91
+ if save != data[:status][:general] then
92
+ raise Sc4ry::Exceptions::CircuitBreaked if data[:status][:general] == :open and data[:raise_on_opening]
93
+ Sc4ry::Helpers.notify circuit: options[:circuit], config: data
94
+ end
90
95
  @@circuits_store.put key: options[:circuit], value: data
91
96
  end
92
97
  end
@@ -13,7 +13,9 @@ require 'uri'
13
13
  require 'json'
14
14
 
15
15
 
16
+
16
17
  require_relative 'helpers'
18
+ require_relative 'exceptions'
17
19
  require_relative 'logger'
18
20
  require_relative 'backends/init'
19
21
  require_relative 'store'
@@ -0,0 +1,11 @@
1
+ module Sc4ry
2
+ module Exceptions
3
+ class CircuitBreaked < StandardError
4
+ def initialize(msg="Circuit just opened")
5
+ super(msg)
6
+ end
7
+
8
+ end
9
+
10
+ end
11
+ end
@@ -43,7 +43,12 @@ module Sc4ry
43
43
  elsif @circuit[:exceptions].include? e.class
44
44
  @failure = true
45
45
  else
46
- Sc4ry::Loggers.warning "skipped : #{@last_exception}"
46
+ if @circuit[:forward_unknown_exceptions] then
47
+ raise e.class, "Sc4ry forward: #{e.message}"
48
+ else
49
+ Sc4ry::Helpers.log level: :debug, message: "skipped : #{@last_exception}"
50
+ end
51
+
47
52
  end
48
53
  end
49
54
  @end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
data/lib/sc4ry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sc4ry
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.5"
3
3
  end
data/sc4ry.gemspec CHANGED
@@ -19,4 +19,9 @@ Gem::Specification.new do |spec|
19
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
20
  end
21
21
  spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "prometheus-client", "~> 3.0"
24
+ spec.add_dependency "rest-client", "~> 2.1"
25
+
26
+
22
27
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sc4ry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prometheus-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
13
41
  description: Sc4ry provide the design pattern Circuit breaker for your application.
14
42
  email:
15
43
  - romain.georges@orange.com
@@ -33,6 +61,7 @@ files:
33
61
  - lib/sc4ry/backends/redis.rb
34
62
  - lib/sc4ry/circuits.rb
35
63
  - lib/sc4ry/dependencies.rb
64
+ - lib/sc4ry/exceptions.rb
36
65
  - lib/sc4ry/exporters/init.rb
37
66
  - lib/sc4ry/helpers.rb
38
67
  - lib/sc4ry/logger.rb