Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0903507

Browse filesBrowse files
committed
Integrate state store into system lights
1 parent 893878d commit 0903507
Copy full SHA for 0903507

File tree

Expand file treeCollapse file tree

3 files changed

+33
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+33
-8
lines changed
Open diff view settings
Collapse file

‎lib/stoplight/infrastructure/storage/fail_safe/state.rb‎

Copy file name to clipboardExpand all lines: lib/stoplight/infrastructure/storage/fail_safe/state.rb
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class State < Domain::Storage::State
2626
# @return [Stoplight::Light] The circuit breaker used to handle store failures.
2727
private attr_reader :circuit_breaker
2828

29-
# @param primary_store [Stoplight::Domain::Storage::RecoveryLock]
29+
# @param primary_store [Stoplight::Domain::Storage::State]
3030
# @param error_notifier [Proc]
31-
# @param failover_store [Stoplight::Domain::Storage::RecoveryLock]
31+
# @param failover_store [Stoplight::Domain::Storage::State]
3232
# @param circuit_breaker [Stoplight::Domain::Light]
3333
def initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:)
3434
@primary_store = primary_store
@@ -45,6 +45,7 @@ def set_state(state)
4545
end
4646
end
4747

48+
# @return [Stoplight::Domain::StateSnapshot]
4849
def state_snapshot
4950
circuit_breaker.run(fallback { failover_store.state_snapshot }) do
5051
primary_store.state_snapshot
Collapse file

‎lib/stoplight/infrastructure/storage/memory/state.rb‎

Copy file name to clipboardExpand all lines: lib/stoplight/infrastructure/storage/memory/state.rb
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ module Memory
3030
# @see Stoplight::Domain::Storage::State for the interface contract
3131
#
3232
class State < Domain::Storage::State
33-
# @!attribute recovered_at
34-
# @return [Time, nil]
35-
private attr_accessor :recovered_at
36-
3733
# @!attribute locked_state
3834
# @return [String]
3935
private attr_accessor :locked_state
4036

37+
# @!attribute recovered_at
38+
# @return [Time, nil]
39+
private attr_accessor :recovered_at
40+
4141
# @!attribute recovery_scheduled_after
4242
# @return [Time, nil]
4343
private attr_accessor :recovery_scheduled_after
@@ -72,7 +72,7 @@ def initialize(clock:, cool_off_time:)
7272
end
7373

7474
# @param state [String]
75-
# @return [void]
75+
# @return [String]
7676
def set_state(state)
7777
mutex.synchronize do
7878
self.locked_state = state
Collapse file

‎lib/stoplight/wiring/system/light_builder.rb‎

Copy file name to clipboardExpand all lines: lib/stoplight/wiring/system/light_builder.rb
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,42 @@ module Wiring
55
class System
66
class LightBuilder < Wiring::LightBuilder
77
private attr_reader :system
8+
private attr_reader :clock
89

910
def initialize(system, settings)
1011
@system = system
12+
@clock = Infrastructure::SystemClock.new
1113

1214
super(settings)
1315
end
1416

15-
def key_space = Infrastructure::Storage::Redis::KeySpace.build(
17+
def key_space = @key_space ||= Infrastructure::Storage::Redis::KeySpace.build(
1618
system_name: system.name,
1719
light_name: config.name
1820
)
1921

22+
def cool_off_time = config.cool_off_time
23+
24+
private def state_store
25+
@state_store ||= case data_store_config
26+
in Stoplight::DataStore::Memory
27+
Infrastructure::Storage::Memory::State.new(clock:, cool_off_time:)
28+
in Stoplight::DataStore::Redis
29+
Infrastructure::Storage::FailSafe::State.new(
30+
primary_store: Infrastructure::Storage::Redis::State.new(
31+
redis: data_store_config.redis,
32+
scripting:,
33+
key_space:,
34+
cool_off_time:,
35+
clock:
36+
),
37+
error_notifier:,
38+
failover_store: Infrastructure::Storage::Memory::State.new(clock:, cool_off_time:),
39+
circuit_breaker: failover_system.light("redis")
40+
)
41+
end
42+
end
43+
2044
def failover_system = @failover_system ||= Stoplight.__stoplight__system("failover-#{system.name}")
2145
end
2246
end

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.