Class: Stoplight::Infrastructure::FailSafe::DataStore Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/fail_safe/data_store.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 data store that provides fail-safe mechanisms using a circuit breaker. It ensures that operations on the data store can gracefully handle failures by falling back to default values when necessary.

steep:ignore:start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_store:, error_notifier:, failover_data_store:, circuit_breaker:) ⇒ DataStore

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



23
24
25
26
27
28
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 23

def initialize(data_store:, error_notifier:, failover_data_store:, circuit_breaker:)
  @data_store = data_store
  @error_notifier = error_notifier
  @failover_data_store = failover_data_store
  @circuit_breaker = circuit_breaker
end

Instance Attribute Details

#data_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 data store being used



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

def data_store
  @data_store
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.



17
18
19
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 17

def error_notifier
  @error_notifier
end

#failover_data_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 data store used when the primary fails.



19
20
21
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 19

def failover_data_store
  @failover_data_store
end

Instance Method Details

#==(other) ⇒ 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.



134
135
136
137
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 134

def ==(other)
  other.is_a?(self.class) && other.data_store == data_store && other.error_notifier == error_notifier &&
    other.failover_data_store == failover_data_store
end

#acquire_recovery_lock(config) ⇒ 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.

Parameters:



109
110
111
112
113
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 109

def acquire_recovery_lock(config)
  with_fallback(:acquire_recovery_lock, config) do
    data_store.acquire_recovery_lock(config)
  end
end

#clear_metrics(config) ⇒ 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.



54
55
56
57
58
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 54

def clear_metrics(config)
  with_fallback(:clear_metrics, config) do
    data_store.clear_metrics(config)
  end
end

#clear_recovery_metrics(config) ⇒ 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.



60
61
62
63
64
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 60

def clear_recovery_metrics(config)
  with_fallback(:clear_recovery_metrics, config) do
    data_store.clear_recovery_metrics(config)
  end
end

#delete_light(config, *args, **kwargs) ⇒ 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.



102
103
104
105
106
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 102

def delete_light(config, *args, **kwargs)
  with_fallback(:delete_light, config, *args, **kwargs) do
    data_store.delete_light(config, *args, **kwargs)
  end
end

#get_metrics(config, *args, **kwargs) ⇒ 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.



36
37
38
39
40
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 36

def get_metrics(config, *args, **kwargs)
  with_fallback(:get_metrics, config, *args, **kwargs) do
    data_store.get_metrics(config, *args, **kwargs)
  end
end

#get_recovery_metrics(config, *args, **kwargs) ⇒ 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.



42
43
44
45
46
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 42

def get_recovery_metrics(config, *args, **kwargs)
  with_fallback(:get_recovery_metrics, config, *args, **kwargs) do
    data_store.get_recovery_metrics(config, *args, **kwargs)
  end
end

#get_state_snapshot(config) ⇒ 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.



48
49
50
51
52
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 48

def get_state_snapshot(config)
  with_fallback(:get_state_snapshot, config) do
    data_store.get_state_snapshot(config)
  end
end

#namesObject

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.



30
31
32
33
34
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 30

def names
  with_fallback(:names) do
    data_store.names
  end
end

#record_failure(config, *args, **kwargs) ⇒ 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.



66
67
68
69
70
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 66

def record_failure(config, *args, **kwargs)
  with_fallback(:record_failure, config, *args, **kwargs) do
    data_store.record_failure(config, *args, **kwargs)
  end
end

#record_recovery_probe_failure(config, *args, **kwargs) ⇒ 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.



84
85
86
87
88
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 84

def record_recovery_probe_failure(config, *args, **kwargs)
  with_fallback(:record_recovery_probe_failure, config, *args, **kwargs) do
    data_store.record_recovery_probe_failure(config, *args, **kwargs)
  end
end

#record_recovery_probe_success(config, *args, **kwargs) ⇒ 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.



78
79
80
81
82
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 78

def record_recovery_probe_success(config, *args, **kwargs)
  with_fallback(:record_recovery_probe_success, config, *args, **kwargs) do
    data_store.record_recovery_probe_success(config, *args, **kwargs)
  end
end

#record_success(config, *args, **kwargs) ⇒ 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.



72
73
74
75
76
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 72

def record_success(config, *args, **kwargs)
  with_fallback(:record_success, config, *args, **kwargs) do
    data_store.record_success(config, *args, **kwargs)
  end
end

#release_recovery_lock(recovery_lock_token) ⇒ 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.

Routes release to correct store based on token type. Redis tokens release via primary (with error notification on failure). Memory tokens release via failover directly.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 119

def release_recovery_lock(recovery_lock_token)
  case recovery_lock_token
  in Redis::DataStore::RecoveryLockToken
    fallback = proc do |error|
      error_notifier.call(error) if error
    end

    circuit_breaker.run(fallback) do
      data_store.release_recovery_lock(recovery_lock_token)
    end
  in Memory::DataStore::RecoveryLockToken
    failover_data_store.release_recovery_lock(recovery_lock_token)
  end
end

#set_state(config, *args, **kwargs) ⇒ 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.



90
91
92
93
94
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 90

def set_state(config, *args, **kwargs)
  with_fallback(:set_state, config, *args, **kwargs) do
    data_store.set_state(config, *args, **kwargs)
  end
end

#transition_to_color(config, *args, **kwargs) ⇒ 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.



96
97
98
99
100
# File 'lib/stoplight/infrastructure/fail_safe/data_store.rb', line 96

def transition_to_color(config, *args, **kwargs)
  with_fallback(:transition_to_color, config, *args, **kwargs) do
    data_store.transition_to_color(config, *args, **kwargs)
  end
end