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

Method Summary

Methods included from ImmutableOptions

#initialize

Instance Attribute Details

#cacheCache::Interface (readonly)

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

Returns:


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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].


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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 [].


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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:


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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.


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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:


82
83
84
85
86
87
88
89
90
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
# File 'lib/faulty/circuit.rb', line 82

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

  private

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

  def required
    %i[
      cache
      cool_down
      errors
      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