Class: Stoplight::Infrastructure::FailSafe::Storage::Metrics Private
- Inherits:
-
Object
- Object
- Stoplight::Infrastructure::FailSafe::Storage::Metrics
- Includes:
- Domain::_MetricsStore
- Defined in:
- lib/stoplight/infrastructure/fail_safe/storage/metrics.rb,
sig/_private/stoplight/infrastructure/fail_safe/storage/metrics.rbs
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A wrapper around a store that provides fail-safe mechanisms using a circuit breaker. It ensures that operations on the store can gracefully handle failures by falling back to default values when necessary.
Instance Attribute Summary collapse
-
#circuit_breaker ⇒ Domain::Light
readonly
private
The circuit breaker used to handle store failures.
- #error_notifier ⇒ error_notifier readonly private
-
#failover_store ⇒ Domain::_MetricsStore
readonly
private
The fallback store used when the primary fails.
-
#primary_store ⇒ Domain::_MetricsStore
readonly
private
The underlying primary store being used.
Instance Method Summary collapse
- #clear ⇒ Object private
- #fallback(&fallback) ⇒ void private
-
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ Metrics
constructor
private
A new instance of Metrics.
- #metrics_snapshot ⇒ Object private
- #record_failure(exception) ⇒ Object private
- #record_success ⇒ Object private
Constructor Details
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ Metrics
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Metrics.
19 20 21 22 23 24 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 19 def initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) @primary_store = primary_store @error_notifier = error_notifier @failover_store = failover_store @circuit_breaker = circuit_breaker end |
Instance Attribute Details
#circuit_breaker ⇒ Domain::Light (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The circuit breaker used to handle store failures.
53 54 55 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 53 def circuit_breaker @circuit_breaker end |
#error_notifier ⇒ error_notifier (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 15 def error_notifier @error_notifier end |
#failover_store ⇒ Domain::_MetricsStore (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The fallback store used when the primary fails.
17 18 19 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 17 def failover_store @failover_store end |
#primary_store ⇒ Domain::_MetricsStore (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The underlying primary store being used
14 15 16 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 14 def primary_store @primary_store end |
Instance Method Details
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 48 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 44 def clear circuit_breaker.run(fallback { failover_store.clear }) do primary_store.clear end end |
#fallback(&fallback) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
55 56 57 58 59 60 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 55 def fallback(&fallback) ->(error) { error_notifier.call(error) if error fallback.call } end |
#metrics_snapshot ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 26 def metrics_snapshot circuit_breaker.run(fallback { failover_store.metrics_snapshot }) do primary_store.metrics_snapshot end end |
#record_failure(exception) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 38 def record_failure(exception) circuit_breaker.run(fallback { failover_store.record_failure(exception) }) do primary_store.record_failure(exception) end end |
#record_success ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/metrics.rb', line 32 def record_success circuit_breaker.run(fallback { failover_store.record_success }) do primary_store.record_success end end |