stoplight 5.3.8 → 5.5.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -1
  3. data/lib/generators/stoplight/install/templates/stoplight.rb.erb +2 -0
  4. data/lib/stoplight/admin/views/layout.erb +3 -3
  5. data/lib/stoplight/admin.rb +4 -4
  6. data/lib/stoplight/domain/color.rb +11 -0
  7. data/lib/stoplight/{config → domain}/compatibility_result.rb +1 -1
  8. data/lib/stoplight/domain/config.rb +55 -0
  9. data/lib/stoplight/{data_store/base.rb → domain/data_store.rb} +17 -15
  10. data/lib/stoplight/domain/error.rb +42 -0
  11. data/lib/stoplight/domain/failure.rb +42 -0
  12. data/lib/stoplight/domain/light/configuration_builder_interface.rb +130 -0
  13. data/lib/stoplight/domain/light.rb +198 -0
  14. data/lib/stoplight/domain/light_factory.rb +75 -0
  15. data/lib/stoplight/domain/metadata.rb +65 -0
  16. data/lib/stoplight/domain/state.rb +11 -0
  17. data/lib/stoplight/{notifier/base.rb → domain/state_transition_notifier.rb} +5 -4
  18. data/lib/stoplight/domain/strategies/green_run_strategy.rb +69 -0
  19. data/lib/stoplight/domain/strategies/red_run_strategy.rb +41 -0
  20. data/lib/stoplight/domain/strategies/run_strategy.rb +27 -0
  21. data/lib/stoplight/domain/strategies/yellow_run_strategy.rb +98 -0
  22. data/lib/stoplight/domain/tracker/base.rb +41 -0
  23. data/lib/stoplight/domain/tracker/recovery_probe.rb +72 -0
  24. data/lib/stoplight/domain/tracker/request.rb +67 -0
  25. data/lib/stoplight/domain/traffic_control/base.rb +74 -0
  26. data/lib/stoplight/domain/traffic_control/consecutive_errors.rb +57 -0
  27. data/lib/stoplight/domain/traffic_control/error_rate.rb +51 -0
  28. data/lib/stoplight/domain/traffic_recovery/base.rb +79 -0
  29. data/lib/stoplight/domain/traffic_recovery/consecutive_successes.rb +70 -0
  30. data/lib/stoplight/domain/traffic_recovery.rb +13 -0
  31. data/lib/stoplight/infrastructure/data_store/memory/sliding_window.rb +79 -0
  32. data/lib/stoplight/infrastructure/data_store/memory.rb +307 -0
  33. data/lib/stoplight/infrastructure/data_store/redis/lua.rb +25 -0
  34. data/lib/stoplight/infrastructure/data_store/redis.rb +478 -0
  35. data/lib/stoplight/infrastructure/dependency_injection/container.rb +249 -0
  36. data/lib/stoplight/infrastructure/dependency_injection/unresolved_dependency_error.rb +13 -0
  37. data/lib/stoplight/infrastructure/notifier/generic.rb +90 -0
  38. data/lib/stoplight/infrastructure/notifier/io.rb +23 -0
  39. data/lib/stoplight/infrastructure/notifier/logger.rb +21 -0
  40. data/lib/stoplight/rspec/generic_notifier.rb +1 -1
  41. data/lib/stoplight/version.rb +1 -1
  42. data/lib/stoplight/wiring/container.rb +80 -0
  43. data/lib/stoplight/wiring/default.rb +28 -0
  44. data/lib/stoplight/{config/user_default_config.rb → wiring/default_configuration.rb} +24 -31
  45. data/lib/stoplight/wiring/default_factory_builder.rb +25 -0
  46. data/lib/stoplight/wiring/fail_safe_data_store.rb +123 -0
  47. data/lib/stoplight/{notifier/fail_safe.rb → wiring/fail_safe_notifier.rb} +22 -13
  48. data/lib/stoplight/wiring/light/default_config.rb +18 -0
  49. data/lib/stoplight/wiring/light/system_config.rb +11 -0
  50. data/lib/stoplight/wiring/light_factory.rb +188 -0
  51. data/lib/stoplight/wiring/public_api.rb +28 -0
  52. data/lib/stoplight/wiring/system_container.rb +9 -0
  53. data/lib/stoplight/wiring/system_light_factory.rb +17 -0
  54. data/lib/stoplight.rb +38 -28
  55. metadata +53 -42
  56. data/lib/stoplight/color.rb +0 -9
  57. data/lib/stoplight/config/dsl.rb +0 -97
  58. data/lib/stoplight/config/library_default_config.rb +0 -21
  59. data/lib/stoplight/config/system_config.rb +0 -7
  60. data/lib/stoplight/data_store/fail_safe.rb +0 -113
  61. data/lib/stoplight/data_store/memory.rb +0 -311
  62. data/lib/stoplight/data_store/redis/lua.rb +0 -23
  63. data/lib/stoplight/data_store/redis.rb +0 -449
  64. data/lib/stoplight/data_store.rb +0 -6
  65. data/lib/stoplight/default.rb +0 -30
  66. data/lib/stoplight/error.rb +0 -10
  67. data/lib/stoplight/failure.rb +0 -71
  68. data/lib/stoplight/light/config.rb +0 -111
  69. data/lib/stoplight/light/configuration_builder_interface.rb +0 -128
  70. data/lib/stoplight/light/green_run_strategy.rb +0 -54
  71. data/lib/stoplight/light/red_run_strategy.rb +0 -27
  72. data/lib/stoplight/light/run_strategy.rb +0 -32
  73. data/lib/stoplight/light/yellow_run_strategy.rb +0 -94
  74. data/lib/stoplight/light.rb +0 -191
  75. data/lib/stoplight/metadata.rb +0 -99
  76. data/lib/stoplight/notifier/generic.rb +0 -79
  77. data/lib/stoplight/notifier/io.rb +0 -21
  78. data/lib/stoplight/notifier/logger.rb +0 -19
  79. data/lib/stoplight/state.rb +0 -9
  80. data/lib/stoplight/traffic_control/base.rb +0 -70
  81. data/lib/stoplight/traffic_control/consecutive_errors.rb +0 -55
  82. data/lib/stoplight/traffic_control/error_rate.rb +0 -49
  83. data/lib/stoplight/traffic_recovery/base.rb +0 -75
  84. data/lib/stoplight/traffic_recovery/consecutive_successes.rb +0 -68
  85. data/lib/stoplight/traffic_recovery.rb +0 -11
  86. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/get_metadata.lua +0 -0
  87. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/record_failure.lua +0 -0
  88. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/record_success.lua +0 -0
  89. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/transition_to_green.lua +0 -0
  90. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/transition_to_red.lua +0 -0
  91. /data/lib/stoplight/{data_store → infrastructure/data_store}/redis/transition_to_yellow.lua +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e14702003b76fde01b28e5266b392f5d55b2924c83365a0ab122f11aebf2e4a7
4
- data.tar.gz: e9c1b348b2637aa66408de62a2bbbc24b9b73927ca9712a8b4137446e336cd0a
3
+ metadata.gz: 297bbf636a9d6fa8e47b2241a3bfe0ccf357954044dc9cd02b79735012d92148
4
+ data.tar.gz: 7e539fac482dbde352b0e971b20d29968758c85017c2f917859d5130ef8ed7a1
5
5
  SHA512:
6
- metadata.gz: 1601dd8a7fae2e9c8f89a52556c8f931d3712d71648300aef0e3dae226c9998b7b1fa35e7fa0ce151d943e961473e012ca382b718bb50b44000f5a43e4d667b8
7
- data.tar.gz: 7c4e9696009e01bea1908cd3212d4625cc0ac3e03205d1cd69e4471f9aec4f3add7f101e58b393df210658e6be2c2d42b5d4a2ddedd954f832053505e291f232
6
+ metadata.gz: 53277c7ec692204dc99c96dbf4d8e224d47424b6f5605445de2dc9122d09adedcb683ca783be7f0496db0b6e9aef9045636100da889055e0cb0ee4a4c398ab1e
7
+ data.tar.gz: f0dd133ab0aa988a9bac5d9b2954299c5cf47ee86f08482b0199c8108fe953ae6e44c5f781457cda74063a93d1686da9ce76b4e4780ffb16d66dd70790b17815
data/README.md CHANGED
@@ -99,6 +99,19 @@ light.run { 1 / 0 } #=> raises Stoplight::Error::RedLight: example-zero
99
99
  light.color # => "red"
100
100
  ```
101
101
 
102
+ The `Stoplight::Error::RedLight` provides metadata about the error:
103
+
104
+ ```ruby
105
+ def run_request
106
+ light = Stoplight("Example", cool_off_time: 10)
107
+ light.run { 1 / 0 } #=> raises Stoplight::Error::RedLight
108
+ rescue Stoplight::Error::RedLight => error
109
+ puts error.light_name #=> "Example"
110
+ puts error.cool_off_time #=> 10
111
+ puts error.retry_after #=> Absolute Time after which a recovery attempt can occur (e.g., "2025-10-21 15:39:50.672414 +0600")
112
+ end
113
+ ```
114
+
102
115
  After one minute, the light transitions to yellow, allowing a test execution:
103
116
 
104
117
  ```ruby
@@ -131,6 +144,8 @@ receives `nil`. In both cases, the return value of the fallback becomes the retu
131
144
 
132
145
  Stoplight comes with a built-in Admin Panel that can track all active Lights and manually lock them in the desired state (`Green` or `Red`). Locking lights in certain states might be helpful in scenarios like E2E testing.
133
146
 
147
+ ![Admin Panel Screenshot](assets/admin.png)
148
+
134
149
  To add Admin Panel protected by basic authentication to your Rails project, add this configuration to your `config/routes.rb` file.
135
150
 
136
151
  ```ruby
@@ -613,7 +628,7 @@ Example: "Ruby 3.2 reaches end-of-life in March 2026, so Stoplight 6.0 will requ
613
628
 
614
629
  After checking out the repo, run `bundle install` to install dependencies. Run tests with `bundle exec rspec` and check
615
630
  code style with `bundle exec standardrb`. We follow a git flow branching strategy - see our [Git Flow wiki page] for
616
- details on branch naming, releases, and contribution workflow.
631
+ details on branch naming, releases, and contribution workflow. Also check our CONTRIBUTING.md guide for contributors.
617
632
 
618
633
  ## Credits
619
634
 
@@ -12,7 +12,9 @@ require "redis"
12
12
  # "redis://admin:p4ssw0rd@10.0.1.1:6380/15"
13
13
  redis = Redis.new
14
14
  data_store = Stoplight::DataStore::Redis.new(redis)
15
+ error_notifier = Rails.error.method(:report)
15
16
 
16
17
  Stoplight.configure do |config|
17
18
  config.data_store = data_store
19
+ config.error_notifier = error_notifier
18
20
  end
@@ -6,8 +6,8 @@
6
6
 
7
7
  <title>Stoplight Admin</title>
8
8
 
9
- <script type="module" src="https://cdn.jsdelivr.net/npm/@hotwired/turbo@latest/dist/turbo.es2017-esm.min.js"></script>
10
- <script type="module">
9
+ <script nonce="<%= nonce %>" type="module" src="https://cdn.jsdelivr.net/npm/@hotwired/turbo@latest/dist/turbo.es2017-esm.min.js"></script>
10
+ <script nonce="<%= nonce %>" type="module">
11
11
  document.addEventListener("turbo:load", () => {
12
12
  window.initFlowbite()
13
13
  })
@@ -63,6 +63,6 @@
63
63
  </footer>
64
64
  </div>
65
65
 
66
- <script src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
66
+ <script nonce="<%= nonce %>" src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
67
67
  </body>
68
68
  </html>
@@ -2,11 +2,10 @@
2
2
 
3
3
  begin
4
4
  require "sinatra/base"
5
- require "sinatra/contrib"
6
5
  require "sinatra/json"
7
6
  rescue LoadError
8
7
  raise <<~WARN
9
- "sinatra" and "sinatra-contrib" gems are unavailable and necessery for running Stoplight Admin panel
8
+ "sinatra" and "sinatra-contrib" gems are unavailable and necessary for running Stoplight Admin panel
10
9
  Please add them to your Gemfile and run `bundle install`:
11
10
  gem "sinatra", required: false
12
11
  gem "sinatra-contrib", require: false
@@ -25,13 +24,14 @@ module Stoplight
25
24
  helpers Helpers
26
25
 
27
26
  set :protection, except: %i[json_csrf]
28
- set :data_store, proc { Stoplight.default_config.data_store }
27
+ set :data_store, proc { Stoplight.__stoplight__default_configuration.data_store }
29
28
  set :views, File.join(__dir__, "admin", "views")
29
+ set :nonce, proc { |request| }
30
30
 
31
31
  get "/" do
32
32
  lights, stats = dependencies.stats_action.call
33
33
 
34
- erb :index, locals: stats.merge(lights: lights)
34
+ erb :index, locals: stats.merge(lights: lights, nonce: settings.nonce(request))
35
35
  end
36
36
 
37
37
  get "/stats" do
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ module Domain
5
+ module Color
6
+ GREEN = "green"
7
+ YELLOW = "yellow"
8
+ RED = "red"
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stoplight
4
- module Config
4
+ module Domain
5
5
  # The +CompatibilityResult+ class represents the result of a compatibility check
6
6
  # for a strategy. It provides methods to determine if the strategy is compatible
7
7
  # and to retrieve error messages when it is not.
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ module Domain
5
+ # A +Stoplight::Light+ configuration object.
6
+ #
7
+ # # @!attribute [r] name
8
+ # @return [String]
9
+ #
10
+ # @!attribute [r] cool_off_time
11
+ # @return [Numeric]
12
+ #
13
+ # @!attribute [r] threshold
14
+ # @return [Numeric]
15
+ #
16
+ # @!attribute [r] window_size
17
+ # @return [Numeric]
18
+ #
19
+ # @!attribute [r] tracked_errors
20
+ # @return [Array<StandardError>]
21
+ #
22
+ # @!attribute [r] skipped_errors
23
+ # @return [Array<Exception>]
24
+ #
25
+ # @api private
26
+ Config = Data.define(
27
+ :name,
28
+ :cool_off_time,
29
+ :threshold,
30
+ :recovery_threshold,
31
+ :window_size,
32
+ :tracked_errors,
33
+ :skipped_errors
34
+ ) do
35
+ class << self
36
+ # Creates a new NULL configuration object.
37
+ # @return [Stoplight::Domain::Config]
38
+ def empty
39
+ new(**members.map { |key| [key, nil] }.to_h)
40
+ end
41
+ end
42
+
43
+ # Checks if the given error should be tracked
44
+ #
45
+ # @param error [#==] The error to check, e.g. an Exception, Class or Proc
46
+ # @return [Boolean]
47
+ def track_error?(error)
48
+ skip = skipped_errors.any? { |klass| klass === error }
49
+ track = tracked_errors.any? { |klass| klass === error }
50
+
51
+ !skip && track
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stoplight
4
- module DataStore
4
+ module Domain
5
5
  # @abstract
6
- class Base
6
+ # :nocov:
7
+ class DataStore
7
8
  METRICS_RETENTION_TIME = 60 * 60 * 24 # 1 day
8
9
 
9
10
  # Retrieves the names of all lights stored in the data store.
@@ -15,24 +16,24 @@ module Stoplight
15
16
 
16
17
  # Retrieves metadata for a specific light configuration.
17
18
  #
18
- # @param config [Stoplight::Light::Config] The light configuration.
19
- # @return [Stoplight::Metadata] The metadata associated with the light.
19
+ # @param config [Stoplight::Domain::Config] The light configuration.
20
+ # @return [Stoplight::Domain::Metadata] The metadata associated with the light.
20
21
  def get_metadata(config)
21
22
  raise NotImplementedError
22
23
  end
23
24
 
24
25
  # Records a failure for a specific light configuration.
25
26
  #
26
- # @param config [Stoplight::Light::Config]
27
- # @param failure [Failure] The failure to record.
28
- # @return [Stoplight::Metadata] The metadata associated with the light.
29
- def record_failure(config, failure)
27
+ # @param config [Stoplight::Domain::Config]
28
+ # @param exception [Exception]
29
+ # @return [Stoplight::Domain::Metadata] The metadata associated with the light.
30
+ def record_failure(config, exception)
30
31
  raise NotImplementedError
31
32
  end
32
33
 
33
34
  # Records a success for a specific light configuration.
34
35
  #
35
- # @param config [Stoplight::Light::Config]
36
+ # @param config [Stoplight::Domain::Config]
36
37
  # @return [void]
37
38
  def record_success(config)
38
39
  raise NotImplementedError
@@ -40,24 +41,24 @@ module Stoplight
40
41
 
41
42
  # Records a failed recovery probe for a specific light configuration.
42
43
  #
43
- # @param config [Stoplight::Light::Config]
44
+ # @param config [Stoplight::Domain::Config]
44
45
  # @param failure [Failure]
45
- # @return [Stoplight::Metadata]
46
+ # @return [Stoplight::Domain::Metadata]
46
47
  def record_recovery_probe_failure(config, failure)
47
48
  raise NotImplementedError
48
49
  end
49
50
 
50
51
  # Records a successful recovery probe for a specific light configuration.
51
52
  #
52
- # @param config [Stoplight::Light::Config]
53
- # @return [Stoplight::Metadata]
53
+ # @param config [Stoplight::Domain::Config]
54
+ # @return [Stoplight::Domain::Metadata]
54
55
  def record_recovery_probe_success(config)
55
56
  raise NotImplementedError
56
57
  end
57
58
 
58
59
  # Sets the state of a specific light configuration.
59
60
  #
60
- # @param config [Stoplight::Light::Config]
61
+ # @param config [Stoplight::Domain::Config]
61
62
  # @param state [String] The new state to set.
62
63
  # @return [String] The state that was set.
63
64
  def set_state(config, state)
@@ -71,7 +72,7 @@ module Stoplight
71
72
  # is considered the "first" to perform the transition (and therefore responsible for
72
73
  # triggering notifications).
73
74
  #
74
- # @param config [Stoplight::Light::Config]
75
+ # @param config [Stoplight::Domain::Config]
75
76
  # @param color [String] The target color/state to transition to.
76
77
  # Should be one of Stoplight::Color::GREEN, Stoplight::Color::YELLOW, or Stoplight::Color::RED.
77
78
  #
@@ -88,5 +89,6 @@ module Stoplight
88
89
  raise NotImplementedError
89
90
  end
90
91
  end
92
+ # :nocov:
91
93
  end
92
94
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ module Domain
5
+ module Error
6
+ Base = Class.new(StandardError)
7
+ ConfigurationError = Class.new(Base)
8
+ IncorrectColor = Class.new(Base)
9
+
10
+ class RedLight < Base
11
+ # @!attribute light_name
12
+ # @return [String] The light's name
13
+ attr_reader :light_name
14
+
15
+ # @!attribute cool_off_time
16
+ # @return [Numeric] Cool-off period in seconds
17
+ attr_reader :cool_off_time
18
+
19
+ # @!attribute retry_after
20
+ # @return [Time] Absolute Time after which a recovery attempt can occur
21
+ attr_reader :retry_after
22
+
23
+ # Initializes a new RedLight error.
24
+ #
25
+ # @param light_name [String] The light's name
26
+ #
27
+ # @option cool_off_time [Numeric] Cool-off period in seconds
28
+ #
29
+ # @option retry_after [Time] Absolute Time after which a recovery attempt can occur
30
+ #
31
+ # @return [Stoplight::Error::RedLight]
32
+ def initialize(light_name, cool_off_time:, retry_after:)
33
+ @light_name = light_name
34
+ @cool_off_time = cool_off_time
35
+ @retry_after = retry_after
36
+
37
+ super(light_name)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "time"
5
+
6
+ module Stoplight
7
+ module Domain
8
+ # @api private
9
+ class Failure
10
+ # @return [String]
11
+ attr_reader :error_class
12
+ # @return [String]
13
+ attr_reader :error_message
14
+ # @return [Time]
15
+ attr_reader :time
16
+
17
+ # @param error [Exception]
18
+ # @return (see #initialize)
19
+ def self.from_error(error, time: Time.now)
20
+ new(error.class.name, error.message, time)
21
+ end
22
+
23
+ # @param error_class [String]
24
+ # @param error_message [String]
25
+ # @param time [Time]
26
+ def initialize(error_class, error_message, time)
27
+ @error_class = error_class
28
+ @error_message = error_message
29
+ @time = time
30
+ end
31
+
32
+ # @param other [Failure]
33
+ # @return [Boolean]
34
+ def ==(other)
35
+ other.is_a?(self.class) &&
36
+ error_class == other.error_class &&
37
+ error_message == other.error_message &&
38
+ time == other.time
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module Stoplight
6
+ module Domain
7
+ class Light
8
+ # Implements light configuration behavior
9
+ module ConfigurationBuilderInterface
10
+ # Configures data store to be used with this circuit breaker
11
+ #
12
+ # @example
13
+ # Stoplight('example')
14
+ # .with_data_store(Stoplight::DataStore::Memory.new)
15
+ #
16
+ # @param data_store [DataStore::Base]
17
+ # @return [Stoplight::Light]
18
+ # @deprecated consider using +Light#with+ for reconfiguration
19
+ def with_data_store(data_store)
20
+ with(data_store:)
21
+ end
22
+
23
+ # Configures cool off time. Stoplight automatically tries to recover
24
+ # from the red state after the cool off time.
25
+ #
26
+ # @example
27
+ # Stoplight('example')
28
+ # .cool_off_time(60)
29
+ #
30
+ # @param cool_off_time [Numeric] number of seconds
31
+ # @return [Stoplight::Light]
32
+ # @deprecated consider using +Light#with+ for reconfiguration
33
+ def with_cool_off_time(cool_off_time)
34
+ with(cool_off_time:)
35
+ end
36
+
37
+ # Configures custom threshold. After this number of failures Stoplight
38
+ # switches to the red state:
39
+ #
40
+ # @example
41
+ # Stoplight('example')
42
+ # .with_threshold(5)
43
+ #
44
+ # @param threshold [Numeric]
45
+ # @return [Stoplight::Light]
46
+ # @deprecated consider using +Light#with+ for reconfiguration
47
+ def with_threshold(threshold)
48
+ with(threshold:)
49
+ end
50
+
51
+ # Configures custom window size which Stoplight uses to count failures. For example,
52
+ #
53
+ # @example
54
+ # Stoplight('example')
55
+ # .with_threshold(5)
56
+ # .with_window_size(60)
57
+ #
58
+ # The above example will turn to red light only when 5 errors happen
59
+ # within 60 seconds period.
60
+ #
61
+ # @param window_size [Numeric] number of seconds
62
+ # @return [Stoplight::Light]
63
+ # @deprecated consider using +Light#with+ for reconfiguration
64
+ def with_window_size(window_size)
65
+ with(window_size:)
66
+ end
67
+
68
+ # Configures custom notifier
69
+ #
70
+ # @example
71
+ # io = StringIO.new
72
+ # notifier = Stoplight::Notifier::IO.new(io)
73
+ # Stoplight('example')
74
+ # .with_notifiers([notifier])
75
+ #
76
+ # @param notifiers [Array<Notifier::Base>]
77
+ # @return [Stoplight::Light]
78
+ # @deprecated consider using +Light#with+ for reconfiguration
79
+ def with_notifiers(notifiers)
80
+ with(notifiers:)
81
+ end
82
+
83
+ # @param error_notifier [Proc]
84
+ # @return [Stoplight::Light]
85
+ # @api private
86
+ # @deprecated consider using +Light#with+ for reconfiguration
87
+ def with_error_notifier(&error_notifier)
88
+ with(error_notifier: error_notifier)
89
+ end
90
+
91
+ # Configures a custom list of tracked errors that counts toward the threshold.
92
+ #
93
+ # @example
94
+ # light = Stoplight('example')
95
+ # .with_tracked_errors(TimeoutError, NetworkError)
96
+ # light.run { call_external_service }
97
+ #
98
+ # In the example above, the +TimeoutError+ and +NetworkError+ exceptions
99
+ # will be counted towards the threshold for moving the circuit breaker into the red state.
100
+ # If not configured, the default tracked error is +StandardError+.
101
+ #
102
+ # @param tracked_errors [Array<StandardError>]
103
+ # @return [Stoplight::Light]
104
+ # @deprecated consider using +Light#with+ for reconfiguration
105
+ def with_tracked_errors(*tracked_errors)
106
+ with(tracked_errors:)
107
+ end
108
+
109
+ # Configures a custom list of skipped errors that do not count toward the threshold.
110
+ # Typically, such errors does not represent a real failure and handled somewhere else
111
+ # in the code.
112
+ #
113
+ # @example
114
+ # light = Stoplight('example')
115
+ # .with_skipped_errors(ActiveRecord::RecordNotFound)
116
+ # light.run { User.find(123) }
117
+ #
118
+ # In the example above, the +ActiveRecord::RecordNotFound+ doesn't
119
+ # move the circuit breaker into the red state.
120
+ #
121
+ # @param skipped_errors [Array<Exception>]
122
+ # @return [Stoplight::Light]
123
+ # @deprecated consider using +Light#with+ for reconfiguration
124
+ def with_skipped_errors(*skipped_errors)
125
+ with(skipped_errors:)
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end