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.



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)



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)



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)



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)



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)



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)



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)



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)



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)



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)



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.



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)



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.



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



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