sc4ry 0.1.6 → 0.2.0

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: 6880abfcd193901a6d55d19df6cfe8ad73f407fc1b58aa078f94e3f31c11042f
4
- data.tar.gz: 6a32baa113d73a3f2a76c4df860385296c49382ed4829fdb971e246b79ed1933
3
+ metadata.gz: f4cbfc8c2a7a821c3374916cdd69650a91f1eca5faa4dbbd93ac94e29dae5f89
4
+ data.tar.gz: dfa68d210342122e96e6f9fcd234fa73f6fefee667addac8371424b39c1b63d4
5
5
  SHA512:
6
- metadata.gz: f4471f2769356f0068651aa5d5b4ea218e9a6b0ce608bb76db4ac0bb57f5df1e121df5b912478beea341eadde4f47ddd74c51fd08f651945926b1679d1b19af6
7
- data.tar.gz: a2393c0893d3850ad154efdfe54608927f7f567aa65db4c16f7550fe7a9e681b072c3f2ef0a306e9126040dc347e4a0b4c8535fa637113d57aac399671f54f2d
6
+ metadata.gz: 82590002c1ac457715776b0be304d77fa2903885cc4dc21ee45cea87ee070648661b48520453ab011cd287da49997990b4e607940a54954f5f82b5c884089715
7
+ data.tar.gz: 8b63d6b39cee270a1e1ab38ffcde491b746011126615bc4a5908b9f8790017f0c30c8899453ca1848ee4022f8528a0edd61587b583d58a8404e4eef139ecbb84
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ container-job:
7
+ runs-on: ubuntu-latest
8
+ container: ruby:latest
9
+ services:
10
+ redis:
11
+ image: redis
12
+ pushgateway:
13
+ image: prom/pushgateway
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Run the default task
18
+ run: |
19
+ gem install bundler -v 2.2.3
20
+ bundle install
21
+ bundle exec rake
22
+ env:
23
+ # The hostname used to communicate with the Redis service container
24
+ REDIS_HOST: redis
25
+ REDIS_PORT: 6379
26
+ PROM_PG_PORT: 9091
27
+ PROM_PG_HOST: pushgateway
data/.gitignore CHANGED
@@ -6,6 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ /yardoc/
10
10
  # rspec failure tracking
11
11
  .rspec_status
data/Gemfile CHANGED
@@ -6,4 +6,7 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
8
  gem "prometheus-client", "~> 3.0"
9
- gem "rest-client", "~> 2.1"
9
+ gem "rest-client", "~> 2.1"
10
+ gem "redis", "~> 4.6"
11
+ gem "version", "~> 1.1"
12
+
data/README.md CHANGED
@@ -2,7 +2,25 @@
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_
5
+ [![Ruby](https://github.com/Ultragreen/Sc4ry/workflows/Ruby/badge.svg)](https://github.com/Ultragreen/sc4ry/actions?query=workflow%3ARuby+branch%3Amaster)
6
+ ![GitHub](https://img.shields.io/github/license/Ultragreen/sc4ry)
7
+
8
+ [![Documentation](https://img.shields.io/badge/docs-rubydoc.info-brightgreen)](https://rubydoc.info/gems/sc4ry)
9
+ ![GitHub issues](https://img.shields.io/github/issues/Ultragreen/sc4ry)
10
+ ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Ultragreen/sc4ry)
11
+ ![GitHub top language](https://img.shields.io/github/languages/top/Ultragreen/sc4ry)
12
+ ![GitHub milestones](https://img.shields.io/github/milestones/open/Ultragreen/sc4ry)
13
+
14
+ ![Gem](https://img.shields.io/gem/dt/sc4ry)
15
+ [![Gem Version](https://badge.fury.io/rb/sc4ry.svg)](https://badge.fury.io/rb/sc4ry)
16
+ ![Twitter Follow](https://img.shields.io/twitter/follow/Ultragreen?style=social)
17
+ ![GitHub Org's stars](https://img.shields.io/github/stars/Ultragreen?style=social)
18
+ ![GitHub watchers](https://img.shields.io/github/watchers/Ultragreen/sc4ry?style=social)
19
+
20
+ <noscript><a href="https://liberapay.com/ruydiaz/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></noscript>
21
+
22
+ ![Sc4ry logo](assets/images/logo_sc4ry.png)
23
+ _Simple CircuitBreacker 4 RubY_
6
24
 
7
25
  ## Installation
8
26
 
@@ -22,6 +40,9 @@ Or install it yourself as:
22
40
 
23
41
  ## Usage
24
42
 
43
+ ### Circuits States Worflow
44
+
45
+ ![Sc4ry workflow](assets/images/sc4ry_workflow.png)
25
46
  ### sample with Restclient
26
47
 
27
48
  ```ruby
@@ -30,39 +51,64 @@ require 'rubygems'
30
51
  require 'sc4ry'
31
52
 
32
53
 
54
+ puts 'Initial default config'
55
+ pp Sc4ry::Circuits.default_config
56
+
57
+
58
+ Sc4ry::Circuits.merge_default_config diff: {timeout: true }
59
+ # or with a block
60
+ Sc4ry::Circuits.configure do |spec|
61
+ spec.max_time = 12
62
+ end
63
+
64
+
65
+ # display default config
66
+ puts 'Default config'
67
+ pp Sc4ry::Circuits.default_config
68
+
69
+
33
70
  # 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 }})
71
+ Sc4ry::Circuits.register circuit: :test, config: {:notifiers => [:prometheus,:mattermost], :exceptions => [Errno::ECONNREFUSED, URI::InvalidURIError] }
72
+ # or with a block
73
+ Sc4ry::Circuits.register circuit: :test2 do |spec|
74
+ spec.exceptions = [Errno::ECONNREFUSED]
75
+ end
76
+ # or
77
+ Sc4ry::Circuits.register circuit: :test3
35
78
 
36
- # display the list of known circuit
37
- pp Sc4ry::Circuits.list
38
79
 
39
- # display default config, must be override with a nested hash by calling default_config= method
40
- pp Sc4ry::Circuits.default_config
41
80
 
81
+ puts "Circuits list"
82
+ pp Sc4ry::Circuits::list
42
83
 
43
- # Config an alternate logger
84
+ # Config an alternate logger
44
85
  Sc4ry::Logger.register name: :perso, instance: ::Logger.new('/tmp/logfile.log')
45
- Sc4ry::Logger::current = :perso
86
+ Sc4ry::Logger::current = :stdout
46
87
 
47
88
 
48
89
  # default values, circuit is half open before one of the max count is reached
49
90
 
50
- # {:max_failure_count=>5, => maximum failure before opening circuit
51
- # :timeout_value=>20, => timeout value, if :timeout => true
52
- # :timeout=>false, => (de)activate internal timeout
53
- # :max_timeout_count=>5, => maximum timeout try before opening circuit
54
- # :max_time=>10, => maximum time for a circuit run
55
- # :max_overtime_count=>3, => maximum count of overtime before opening circuit
56
- # :check_delay=>30, => delay after opening, before trying again to closed circuit or after an other check
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
60
- # :exceptions=>[StandardError, RuntimeError]} => list of selected Exceptions considered for failure, others are SKIPPED.
91
+ # DEFAULT_CONFIG = {
92
+ # :max_failure_count => 5,
93
+ # :timeout_value => 20,
94
+ # :timeout => false,
95
+ # :max_timeout_count => 5,
96
+ # :max_time => 10,
97
+ # :max_overtime_count => 3,
98
+ # :check_delay => 30,
99
+ # :notifiers => [],
100
+ # :forward_unknown_exceptions => true,
101
+ # :raise_on_opening => false,
102
+ # :exceptions => [StandardError, RuntimeError]
103
+ # }
61
104
 
62
105
  # display configuration for a specific circuit
63
- pp Sc4ry::Circuits.get circuit: :test
106
+ Sc4ry::Circuits::list.each do |circuit|
107
+ puts "Config #{circuit} :"
108
+ pp Sc4ry::Circuits.get circuit: circuit
109
+ end
64
110
 
65
- # sample Mattermost notification
111
+ # sample Mattermost notification
66
112
  #Sc4ry::Notifiers::config({:name => :mattermost, :config => {:url => 'https://mattermost.mycorp.com', :token => "<TOKEN>"}})
67
113
 
68
114
  # sample loop
@@ -70,7 +116,7 @@ pp Sc4ry::Circuits.get circuit: :test
70
116
  sleep 1
71
117
  Sc4ry::Circuits.run circuit: :test do
72
118
  # for the test choose or build an endpoint you must shutdown
73
- puts RestClient.get('http://<URL_OF_A_ENDPOINT>')
119
+ puts RestClient.get('http://<URL_OF_AN_ENDPOINT>')
74
120
  end
75
121
  end
76
122
 
@@ -84,8 +130,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
84
130
 
85
131
  ## Contributing
86
132
 
87
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sc4ry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sc4ry/blob/master/CODE_OF_CONDUCT.md).
88
-
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Ultragreen/sc4ry.
89
134
 
90
135
  ## License
91
136
 
data/Rakefile CHANGED
@@ -1,6 +1,37 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'yard'
4
+ require 'yard/rake/yardoc_task.rb'
5
+ require 'code_statistics'
6
+ require "roodi"
7
+ require "roodi_task"
8
+ require "version"
9
+ require 'rake/version_task'
10
+ Rake::VersionTask.new
11
+
12
+
13
+ RoodiTask.new() do | t |
14
+ t.patterns = %w(lib/**/*.rb)
15
+ t.config = "ultragreen_roodi_coding_convention.yml"
16
+ end
17
+
3
18
 
4
19
  RSpec::Core::RakeTask.new(:spec)
5
20
 
6
21
  task :default => :spec
22
+
23
+
24
+ YARD::Rake::YardocTask.new do |t|
25
+ t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
26
+ t.options += ['-o', "yardoc"]
27
+ end
28
+ YARD::Config.load_plugin('yard-rspec')
29
+
30
+ namespace :yardoc do
31
+ task :clobber do
32
+ rm_r "yardoc" rescue nil
33
+ rm_r ".yardoc" rescue nil
34
+ rm_r "pkg" rescue nil
35
+ end
36
+ end
37
+ task :clobber => "yardoc:clobber"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
Binary file
@@ -1,33 +1,60 @@
1
+ # Sc4ry module
2
+ # @note namespace
1
3
  module Sc4ry
4
+
5
+ # Sc4ry:Backends module
6
+ # @note namespace
2
7
  module Backends
3
8
 
9
+ # class of the memory backend
4
10
  class Memory
11
+
12
+ # Constructor
13
+ # @param [Hash] config Config map
14
+ # @return [Sc4ry::Backends::Memory] a in Memory backend
5
15
  def initialize(config=nil?)
6
16
  @data = Hash::new
7
17
  end
8
18
 
19
+ # return the list of find records in backend for a specific pattern
20
+ # @return [Array] list of record (for all hostname if hostname is specified)
9
21
  def list
10
22
  return @data.keys
11
23
  end
12
24
 
13
- def get(options)
14
- return @data[options[:key]]
25
+ # return value of queried record
26
+ # @param key [Symbol] the name of the record
27
+ # @return [String] content value of record
28
+ def get(key: )
29
+ return @data[key]
15
30
  end
16
31
 
17
- def put(options)
18
- @data[options[:key]] = options[:value]
32
+ # defined and store value for specified key
33
+ # @param key [Symbol] :key the name of the record
34
+ # @param value [Symbol] :value the content value of the record
35
+ # @return [String] content value of record
36
+ def put(key:, value: )
37
+ @data[key] = value
19
38
  end
20
39
 
21
- def del(options)
22
- @data.delete options[:key]
40
+ # delete a specific record
41
+ # @param params [Symbol] the name of the record
42
+ # @return [Boolean] status of the operation
43
+ def del(key: )
44
+ @data.delete key
23
45
  end
24
46
 
47
+ # flush all records in backend
48
+ # @return [Boolean] status of the operation
25
49
  def flush
26
50
  @data.clear
27
51
  end
28
52
 
29
- def exist?(options)
30
- return @data.include? options[:key]
53
+ # verifiy a specific record existence
54
+ # @param key [Symbol] the name of the record
55
+ # @return [Boolean] presence of the record
56
+ def exist?(key: )
57
+ return @data.include? key
31
58
  end
32
59
 
33
60
  end
@@ -16,46 +16,47 @@ module Sc4ry
16
16
  # return the list of find records in backend for a specific pattern
17
17
  # @return [Array] list of record (for all hostname if hostname is specified)
18
18
  def list
19
- return @store.keys('*')
19
+ return @be.keys('*').map(&:to_sym)
20
20
  end
21
21
 
22
22
 
23
23
  # return value of queried record
24
- # @param [Hash] options
25
- # @option options [Symbol] :key the name of the record
24
+ # @param key [Symbol] the name of the record
26
25
  # @return [String] content value of record
27
- def get(options)
28
- return @store.get(options[:key])
26
+ def get(key:)
27
+ res = YAML.load(@be.get(key))
28
+ res[:exceptions].map! {|item| item = Object.const_get(item) if item.class == String }
29
+ return res
29
30
  end
30
31
 
31
32
  # defined and store value for specified key
32
- # @param [Hash] options
33
- # @option options [Symbol] :key the name of the record
34
- # @option options [Symbol] :value the content value of the record
33
+ # @param key [Symbol] :key the name of the record
34
+ # @param value [Symbol] :value the content value of the record
35
35
  # @return [String] content value of record
36
- def put(options)
37
- @store.set options[:key], options[:value]
36
+ def put(key: ,value:)
37
+ data = value.dup
38
+ data[:exceptions].map! {|item| item = item.name.to_s if item.class == Class }
39
+ @be.set key, data.to_yaml
38
40
  end
39
41
 
40
42
  # delete a specific record
41
- # @param [Hash] options
42
- # @option options [Symbol] :key the name of the record
43
+ # @param key [Symbol] the name of the record
43
44
  # @return [Boolean] status of the operation
44
- def del(options)
45
- @store.del options[:key]
45
+ def del(key: )
46
+ @be.del key
46
47
  end
47
48
 
48
49
  # flush all records in backend
50
+ # @return [Boolean] status of the operation
49
51
  def flush
50
- @store.flushdb
52
+ @be.flushdb
51
53
  end
52
54
 
53
- # verifiy a specific record existance
54
- # @param [Hash] options
55
- # @option options [Symbol] :key the name of the record
55
+ # verifiy a specific record existence
56
+ # @param key [Symbol] the name of the record
56
57
  # @return [Boolean] presence of the record
57
- def exist?(options)
58
- return ( not @store.get(options[:key]).nil?)
58
+ def exist?(key: )
59
+ return ( not @be.get(key).nil?)
59
60
  end
60
61
 
61
62