Class: Stoplight::Infrastructure::FailSafe::Storage::State Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/fail_safe/storage/state.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:) ⇒ State

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 State.



18
19
20
21
22
23
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 18

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_breakerObject (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.



16
17
18
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 16

def circuit_breaker
  @circuit_breaker
end

#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.



14
15
16
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 14

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.



15
16
17
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 15

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.



13
14
15
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 13

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.



46
47
48
49
50
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 46

def clear
  circuit_breaker.run(fallback { failover_store.clear }) do
    primary_store.clear
  end
end

#set_state(state) ⇒ 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.



25
26
27
28
29
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 25

def set_state(state)
  circuit_breaker.run(fallback { failover_store.set_state(state) }) do
    primary_store.set_state(state)
  end
end

#state_snapshotStoplight::Domain::StateSnapshot

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/state.rb', line 32

def state_snapshot
  circuit_breaker.run(fallback { failover_store.state_snapshot }) do
    primary_store.state_snapshot
  end
end

#transition_to_color(color) ⇒ Boolean

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.

Parameters:

  • color (String)

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 40

def transition_to_color(color)
  circuit_breaker.run(fallback { failover_store.transition_to_color(color) }) do
    primary_store.transition_to_color(color)
  end
end