workarea-circuit_breaker 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/ci.yml +66 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +2 -0
- data/.stylelintrc.json +8 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +12 -0
- data/LICENSE +52 -0
- data/README.md +103 -0
- data/Rakefile +59 -0
- data/app/assets/stylesheets/circuit_breaker/.keep +0 -0
- data/app/controllers/workarea/admin/circuits_controller.rb +26 -0
- data/app/view_models/workarea/admin/circuit_view_model.rb +33 -0
- data/app/view_models/workarea/admin/circuits_view_model.rb +41 -0
- data/app/views/workarea/admin/circuits/index.html.haml +69 -0
- data/app/views/workarea/admin/shared/_circuit_breaker_link.html.haml +1 -0
- data/bin/rails +25 -0
- data/config/initializers/appends.rb +4 -0
- data/config/initializers/workarea.rb +11 -0
- data/config/locales/en.yml +29 -0
- data/config/routes.rb +10 -0
- data/lib/workarea/circuit_breaker.rb +96 -0
- data/lib/workarea/circuit_breaker/circuit.rb +137 -0
- data/lib/workarea/circuit_breaker/engine.rb +12 -0
- data/lib/workarea/circuit_breaker/failure_message.rb +51 -0
- data/lib/workarea/circuit_breaker/version.rb +5 -0
- data/script/admin_ci +5 -0
- data/script/ci +8 -0
- data/script/core_ci +5 -0
- data/script/plugins_ci +5 -0
- data/script/storefront_ci +5 -0
- data/test/dummy/.ruby-version +1 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +28 -0
- data/test/dummy/bin/update +28 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +33 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +52 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +45 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +33 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/integration/workarea/admin/circuits_integration_test.rb +27 -0
- data/test/lib/workarea/circuit_breaker/circuit_test.rb +135 -0
- data/test/lib/workarea/circuit_breaker/failure_message_test.rb +41 -0
- data/test/lib/workarea/circuit_breaker_test.rb +42 -0
- data/test/support/circuit_breaker_support.rb +16 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +15 -0
- data/workarea-circuit_breaker.gemspec +17 -0
- metadata +151 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class CircuitBreakerTest < Workarea::TestCase
|
5
|
+
def test_add_service
|
6
|
+
Workarea.with_config do |config|
|
7
|
+
CircuitBreaker.add_service(:fake_service)
|
8
|
+
|
9
|
+
assert(config.circuit_breaker.circuits.has_key?("fake_service"))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_brackets
|
14
|
+
Workarea.with_config do |_config|
|
15
|
+
options = { max_fails: 3, window: 5.minutes, break_for: 5.minutes }
|
16
|
+
CircuitBreaker.add_service(:fake_service, **options)
|
17
|
+
|
18
|
+
circuit = CircuitBreaker[:fake_service]
|
19
|
+
|
20
|
+
assert_equal("fake_service", circuit.name)
|
21
|
+
assert_equal(options, circuit.options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if running_from_source?
|
26
|
+
def test_config_is_frozen
|
27
|
+
Workarea::CircuitBreaker.freeze_config!
|
28
|
+
|
29
|
+
assert(Workarea.config.circuit_breaker.frozen?)
|
30
|
+
assert(Workarea.config.circuit_breaker.circuits.frozen?)
|
31
|
+
assert(Workarea.config.circuit_breaker.circuit_defaults.frozen?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_capture_exception_returns_nil_when_capture_disallowed
|
36
|
+
error = StandardError.new("This will not be captured.")
|
37
|
+
event = CircuitBreaker.capture_exception(error)
|
38
|
+
|
39
|
+
assert_nil(event)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Workarea
|
2
|
+
module CircuitBreakerSupport
|
3
|
+
def with_connection_pool_timeouts(&block)
|
4
|
+
@_original_pool = CircuitBreaker.redis
|
5
|
+
timeout_pool = ConnectionPool.new(timeout: 0, size: 0) do
|
6
|
+
Redis.new(url: Workarea::Configuration::Redis.persistent.to_url)
|
7
|
+
end
|
8
|
+
CircuitBreaker.instance_variable_set(:@redis, timeout_pool)
|
9
|
+
|
10
|
+
block.call
|
11
|
+
|
12
|
+
ensure
|
13
|
+
CircuitBreaker.instance_variable_set(:@redis, @_original_pool)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start 'rails' do
|
3
|
+
add_filter 'lib/workarea/circuit_breaker/version.rb'
|
4
|
+
end
|
5
|
+
|
6
|
+
# Configure Rails Environment
|
7
|
+
ENV['RAILS_ENV'] = 'test'
|
8
|
+
|
9
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
10
|
+
require 'rails/test_help'
|
11
|
+
require 'workarea/test_help'
|
12
|
+
|
13
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
14
|
+
# to be shown.
|
15
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
require "workarea/circuit_breaker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "workarea-circuit_breaker"
|
7
|
+
s.version = Workarea::CircuitBreaker::VERSION
|
8
|
+
s.authors = ["Eric Pigeon"]
|
9
|
+
s.email = ["epigeon@weblinc.com"]
|
10
|
+
s.summary = "Circuit breaker library for Workarea"
|
11
|
+
s.description = "Small libray to implement circuit breaker design pattern around external service calls"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
|
15
|
+
s.add_dependency 'workarea', '~> 3.x'
|
16
|
+
s.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.2'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workarea-circuit_breaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Pigeon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: workarea
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.x
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.x
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.2.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.2.2
|
47
|
+
description: Small libray to implement circuit breaker design pattern around external
|
48
|
+
service calls
|
49
|
+
email:
|
50
|
+
- epigeon@weblinc.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
56
|
+
- ".github/ISSUE_TEMPLATE/documentation-request.md"
|
57
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
58
|
+
- ".github/workflows/ci.yml"
|
59
|
+
- ".gitignore"
|
60
|
+
- ".rubocop.yml"
|
61
|
+
- ".stylelintrc.json"
|
62
|
+
- CHANGELOG.md
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- app/assets/stylesheets/circuit_breaker/.keep
|
68
|
+
- app/controllers/workarea/admin/circuits_controller.rb
|
69
|
+
- app/view_models/workarea/admin/circuit_view_model.rb
|
70
|
+
- app/view_models/workarea/admin/circuits_view_model.rb
|
71
|
+
- app/views/workarea/admin/circuits/index.html.haml
|
72
|
+
- app/views/workarea/admin/shared/_circuit_breaker_link.html.haml
|
73
|
+
- bin/rails
|
74
|
+
- config/initializers/appends.rb
|
75
|
+
- config/initializers/workarea.rb
|
76
|
+
- config/locales/en.yml
|
77
|
+
- config/routes.rb
|
78
|
+
- lib/workarea/circuit_breaker.rb
|
79
|
+
- lib/workarea/circuit_breaker/circuit.rb
|
80
|
+
- lib/workarea/circuit_breaker/engine.rb
|
81
|
+
- lib/workarea/circuit_breaker/failure_message.rb
|
82
|
+
- lib/workarea/circuit_breaker/version.rb
|
83
|
+
- script/admin_ci
|
84
|
+
- script/ci
|
85
|
+
- script/core_ci
|
86
|
+
- script/plugins_ci
|
87
|
+
- script/storefront_ci
|
88
|
+
- test/dummy/.ruby-version
|
89
|
+
- test/dummy/Rakefile
|
90
|
+
- test/dummy/bin/bundle
|
91
|
+
- test/dummy/bin/rails
|
92
|
+
- test/dummy/bin/rake
|
93
|
+
- test/dummy/bin/setup
|
94
|
+
- test/dummy/bin/update
|
95
|
+
- test/dummy/bin/yarn
|
96
|
+
- test/dummy/config.ru
|
97
|
+
- test/dummy/config/application.rb
|
98
|
+
- test/dummy/config/boot.rb
|
99
|
+
- test/dummy/config/environment.rb
|
100
|
+
- test/dummy/config/environments/development.rb
|
101
|
+
- test/dummy/config/environments/production.rb
|
102
|
+
- test/dummy/config/environments/test.rb
|
103
|
+
- test/dummy/config/initializers/application_controller_renderer.rb
|
104
|
+
- test/dummy/config/initializers/assets.rb
|
105
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
106
|
+
- test/dummy/config/initializers/content_security_policy.rb
|
107
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
108
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
109
|
+
- test/dummy/config/initializers/inflections.rb
|
110
|
+
- test/dummy/config/initializers/mime_types.rb
|
111
|
+
- test/dummy/config/initializers/workarea.rb
|
112
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
113
|
+
- test/dummy/config/locales/en.yml
|
114
|
+
- test/dummy/config/puma.rb
|
115
|
+
- test/dummy/config/routes.rb
|
116
|
+
- test/dummy/config/secrets.yml
|
117
|
+
- test/dummy/config/spring.rb
|
118
|
+
- test/dummy/db/seeds.rb
|
119
|
+
- test/dummy/lib/assets/.keep
|
120
|
+
- test/dummy/log/.keep
|
121
|
+
- test/integration/workarea/admin/circuits_integration_test.rb
|
122
|
+
- test/lib/workarea/circuit_breaker/circuit_test.rb
|
123
|
+
- test/lib/workarea/circuit_breaker/failure_message_test.rb
|
124
|
+
- test/lib/workarea/circuit_breaker_test.rb
|
125
|
+
- test/support/circuit_breaker_support.rb
|
126
|
+
- test/teaspoon_env.rb
|
127
|
+
- test/test_helper.rb
|
128
|
+
- workarea-circuit_breaker.gemspec
|
129
|
+
homepage:
|
130
|
+
licenses: []
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Circuit breaker library for Workarea
|
151
|
+
test_files: []
|