Class: Stoplight::Infrastructure::FailSafe::Storage::Metrics Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/fail_safe/storage/metrics.rb

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

Instance Method Summary collapse

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

#error_notifierObject (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_storeObject (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_storeObject (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

#clearObject

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

#metrics_snapshotObject

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_successObject

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