Class: Faulty::Circuit::Options

Inherits:
Struct
  • Object
show all
Includes:
ImmutableOptions
Defined in:
lib/faulty/circuit.rb

Overview

Options for Faulty::Circuit

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImmutableOptions

#dup_with, #initialize, #setup

Instance Attribute Details

#cacheCache::Interface (readonly)

Cache::Null.new. Unlike Faulty#initialize, this is not wrapped in Faulty::Cache::AutoWire by default.

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#cache_expires_inInteger? (readonly)

Returns The number of seconds to keep cached results. A value of nil will keep the cache indefinitely. Default 86400.

Returns:

  • (Integer, nil)

    The number of seconds to keep cached results. A value of nil will keep the cache indefinitely. Default 86400.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#cache_refresh_jitterInteger (readonly)

Returns The maximum number of seconds to randomly add or subtract from cache_refreshes_after when determining whether to refresh the cache. A non-zero value helps reduce a "thundering herd" cache refresh in most scenarios. Set to 0 to disable jitter. Default 0.2 * cache_refreshes_after.

Returns:

  • (Integer)

    The maximum number of seconds to randomly add or subtract from cache_refreshes_after when determining whether to refresh the cache. A non-zero value helps reduce a "thundering herd" cache refresh in most scenarios. Set to 0 to disable jitter. Default 0.2 * cache_refreshes_after.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#cache_refreshes_afterInteger? (readonly)

Returns The number of seconds after which we attempt to refresh the cache even if it's not expired. If the circuit fails, we continue serving the value from cache until cache_expires_in. A value of nil disables cache refreshing. Default 900.

Returns:

  • (Integer, nil)

    The number of seconds after which we attempt to refresh the cache even if it's not expired. If the circuit fails, we continue serving the value from cache until cache_expires_in. A value of nil disables cache refreshing. Default 900.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#cool_downInteger (readonly)

Returns The number of seconds the circuit will stay open after it is tripped. Default 300.

Returns:

  • (Integer)

    The number of seconds the circuit will stay open after it is tripped. Default 300.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#error_mapperModule, #call (readonly)

Returns Used by patches to set the namespace module for the faulty errors that will be raised. Should be a module or a callable. If given a module, the circuit assumes the module has error classes in that module. If given an object that responds to #call (a proc or lambda), the return value of the callable will be used. The callable is called with (error_name, cause_error, circuit). Default Faulty.

Returns:

  • (Module, #call)

    Used by patches to set the namespace module for the faulty errors that will be raised. Should be a module or a callable. If given a module, the circuit assumes the module has error classes in that module. If given an object that responds to #call (a proc or lambda), the return value of the callable will be used. The callable is called with (error_name, cause_error, circuit). Default Faulty



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#errorsError+ (readonly)

Returns An array of errors that are considered circuit failures. Default [StandardError].

Returns:

  • (Error, Array<Error>)

    An array of errors that are considered circuit failures. Default [StandardError].



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#evaluation_windowInteger (readonly)

Returns The number of seconds of history that will be evaluated to determine the failure rate for a circuit. Default 60.

Returns:

  • (Integer)

    The number of seconds of history that will be evaluated to determine the failure rate for a circuit. Default 60.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#excludeError+ (readonly)

Returns An array of errors that will not be captured by Faulty. These errors will not be considered circuit failures. Default [].

Returns:

  • (Error, Array<Error>)

    An array of errors that will not be captured by Faulty. These errors will not be considered circuit failures. Default [].



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#notifierEvents::Notifier (readonly)

Returns A Faulty notifier. Default Events::Notifier.new.

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#rate_thresholdFloat (readonly)

Returns The minimum failure rate required to trip the circuit. For example, 0.5 requires at least a 50% failure rate to trip. Default 0.5.

Returns:

  • (Float)

    The minimum failure rate required to trip the circuit. For example, 0.5 requires at least a 50% failure rate to trip. Default 0.5.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#registryCircuitRegistry (readonly)

memoization of circuits.

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#sample_thresholdInteger (readonly)

Returns The minimum number of runs required before a circuit can trip. A value of 1 means that the circuit will trip immediately when a failure occurs. Default 3.

Returns:

  • (Integer)

    The minimum number of runs required before a circuit can trip. A value of 1 means that the circuit will trip immediately when a failure occurs. Default 3.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

#storageStorage::Interface (readonly)

Storage::Memory.new. Unlike Faulty#initialize, this is not wrapped in Storage::AutoWire by default.

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/faulty/circuit.rb', line 91

Options = Struct.new(
  :cache_expires_in,
  :cache_refreshes_after,
  :cache_refresh_jitter,
  :cool_down,
  :evaluation_window,
  :rate_threshold,
  :sample_threshold,
  :errors,
  :error_mapper,
  :exclude,
  :cache,
  :notifier,
  :storage,
  :registry
) do
  include ImmutableOptions

  # Get the options stored in the storage backend
  #
  # @return [Hash] A hash of stored options
  def for_storage
    {
      cool_down: cool_down,
      evaluation_window: evaluation_window,
      rate_threshold: rate_threshold,
      sample_threshold: sample_threshold
    }
  end

  def defaults
    {
      cache_expires_in: 86_400,
      cache_refreshes_after: 900,
      cool_down: 300,
      errors: [StandardError],
      error_mapper: Faulty,
      exclude: [],
      evaluation_window: 60,
      rate_threshold: 0.5,
      sample_threshold: 3
    }
  end

  def required
    %i[
      cache
      cool_down
      errors
      error_mapper
      exclude
      evaluation_window
      rate_threshold
      sample_threshold
      notifier
      storage
    ]
  end

  def finalize
    self.cache ||= Cache::Default.new
    self.notifier ||= Events::Notifier.new
    self.storage ||= Storage::Memory.new
    self.errors = [errors] if errors && !errors.is_a?(Array)
    self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

    unless cache_refreshes_after.nil?
      self.cache_refresh_jitter = 0.2 * cache_refreshes_after
    end
  end
end

Instance Method Details

#defaultsObject



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/faulty/circuit.rb', line 121

def defaults
  {
    cache_expires_in: 86_400,
    cache_refreshes_after: 900,
    cool_down: 300,
    errors: [StandardError],
    error_mapper: Faulty,
    exclude: [],
    evaluation_window: 60,
    rate_threshold: 0.5,
    sample_threshold: 3
  }
end

#finalizeObject



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/faulty/circuit.rb', line 150

def finalize
  self.cache ||= Cache::Default.new
  self.notifier ||= Events::Notifier.new
  self.storage ||= Storage::Memory.new
  self.errors = [errors] if errors && !errors.is_a?(Array)
  self.exclude = [exclude] if exclude && !exclude.is_a?(Array)

  unless cache_refreshes_after.nil?
    self.cache_refresh_jitter = 0.2 * cache_refreshes_after
  end
end

#for_storageHash

Get the options stored in the storage backend

Returns:

  • (Hash)

    A hash of stored options



112
113
114
115
116
117
118
119
# File 'lib/faulty/circuit.rb', line 112

def for_storage
  {
    cool_down: cool_down,
    evaluation_window: evaluation_window,
    rate_threshold: rate_threshold,
    sample_threshold: sample_threshold
  }
end

#requiredObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/faulty/circuit.rb', line 135

def required
  %i[
    cache
    cool_down
    errors
    error_mapper
    exclude
    evaluation_window
    rate_threshold
    sample_threshold
    notifier
    storage
  ]
end