sc4ry 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -1
- data/assets/images/logo_sc4ry.png +0 -0
- data/assets/logo_sc4ry.png +0 -0
- data/lib/sc4ry/circuits.rb +6 -1
- data/lib/sc4ry/dependencies.rb +2 -0
- data/lib/sc4ry/exceptions.rb +6 -0
- data/lib/sc4ry/logger.rb +2 -2
- data/lib/sc4ry/run_controller.rb +6 -1
- data/lib/sc4ry/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cc6197c11f5b2946c2a7d7ac2057de82866228b4628f5b2d3c0613a3c821ca2
|
4
|
+
data.tar.gz: 306af4cfc3217b7ccc174b9f93407a995faad9fd691b83b0c6848a620313647f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d501193d93a2c0fca6db0b0d7429ff00510253f741347a03a6c6b26b872acb24cb14490ea8a9a61e8b768fce541fbda8c56555e2ba940a1bebe225c4b9065c9b
|
7
|
+
data.tar.gz: e7416163124dee124d7573f37cd2ef51f7d8152105727d057256b5b6738435ab28949c2ebfd5ff5a0d5604b20b40dad32b1ff5f755e3b0b0ab26409b605c710a
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Sc4ry provide the Circuit Breaker Design Pattern for your applications
|
4
4
|
|
5
|
+
![Sc4ry logo](assets/images/logo_sc4ry.png) _Simple CircuitBreacker 4 RubY_
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -20,7 +22,51 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
### sample with Restclient
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'sc4ry'
|
31
|
+
|
32
|
+
|
33
|
+
# defining a circuit, config must be empty or override from default
|
34
|
+
Sc4ry::Circuits.register({:circuit =>:test, :config => {:notifiers => [:prometheus, :mattermost], :exceptions => [Errno::ECONNREFUSED], :timeout => true, :timeout_value => 3, :check_delay => 5 }})
|
35
|
+
|
36
|
+
# display the list of known circuit
|
37
|
+
pp Sc4ry::Circuits.list
|
38
|
+
|
39
|
+
# display default config, must be override with a nested hash by calling default_config= method
|
40
|
+
pp Sc4ry::Circuits.default_config
|
41
|
+
|
42
|
+
# default values, circuit is half open before one of the max count is reached
|
43
|
+
|
44
|
+
# {:max_failure_count=>5, => maximum failure before opening circuit
|
45
|
+
# :timeout_value=>20, => timeout value, if :timeout => true
|
46
|
+
# :timeout=>false, => activate internal timeout
|
47
|
+
# :max_timeout_count=>5, => maximum timeout try before opening circuit
|
48
|
+
# :max_time=>10, => maximum time for a circuit run
|
49
|
+
# :max_overtime_count=>3, => maximum count of overtime before opening circuit
|
50
|
+
# :check_delay=>30, => delay after opening, before trying again to closed circuit or after an other check
|
51
|
+
# :notifiers=>[], => active notifier, must be :symbol in [:prometheus, :mattermost]
|
52
|
+
# :exceptions=>[StandardError, RuntimeError]} => list of selected Exceptions considered for failure, others are SKIPPED.
|
53
|
+
|
54
|
+
# display configuration for a specific circuit
|
55
|
+
pp Sc4ry::Circuits.get circuit: :test
|
56
|
+
|
57
|
+
# sample Mattermost notification
|
58
|
+
#Sc4ry::Notifiers::config({:name => :mattermost, :config => {:url => 'https://mattermost.mycorp.com', :token => "<TOKEN>"}})
|
59
|
+
|
60
|
+
# sample loop
|
61
|
+
100.times do
|
62
|
+
sleep 1
|
63
|
+
Sc4ry::Circuits.run circuit: :test do
|
64
|
+
# for the test choose or build an endpoint you must shutdown
|
65
|
+
puts RestClient.get('http://<URL_OF_A_ENDPOINT>')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
```
|
24
70
|
|
25
71
|
## Development
|
26
72
|
|
Binary file
|
Binary file
|
data/lib/sc4ry/circuits.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/sc4ry/dependencies.rb
CHANGED
data/lib/sc4ry/logger.rb
CHANGED
@@ -18,8 +18,8 @@ module Sc4ry
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def Logger.current=(sym)
|
21
|
-
raise "Logger not define : #{
|
22
|
-
@@
|
21
|
+
raise "Logger not define : #{sym}" unless @@loggers.keys.include? sym
|
22
|
+
@@current = sym
|
23
23
|
end
|
24
24
|
|
25
25
|
def Logger.register(options = {})
|
data/lib/sc4ry/run_controller.rb
CHANGED
@@ -43,7 +43,12 @@ module Sc4ry
|
|
43
43
|
elsif @circuit[:exceptions].include? e.class
|
44
44
|
@failure = true
|
45
45
|
else
|
46
|
-
|
46
|
+
if @circuit[:forward_unknown_exceptions] then
|
47
|
+
raise @last_exception.class, "Sc4ry forward: #{@last_exception.message}"
|
48
|
+
else
|
49
|
+
Sc4ry::Loggers.warning "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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sc4ry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
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-02
|
11
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Sc4ry provide the design pattern Circuit breaker for your application.
|
14
14
|
email:
|
@@ -23,6 +23,8 @@ files:
|
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
|
+
- assets/images/logo_sc4ry.png
|
27
|
+
- assets/logo_sc4ry.png
|
26
28
|
- bin/console
|
27
29
|
- bin/setup
|
28
30
|
- lib/sc4ry.rb
|
@@ -31,6 +33,7 @@ files:
|
|
31
33
|
- lib/sc4ry/backends/redis.rb
|
32
34
|
- lib/sc4ry/circuits.rb
|
33
35
|
- lib/sc4ry/dependencies.rb
|
36
|
+
- lib/sc4ry/exceptions.rb
|
34
37
|
- lib/sc4ry/exporters/init.rb
|
35
38
|
- lib/sc4ry/helpers.rb
|
36
39
|
- lib/sc4ry/logger.rb
|