splitclient-rb 7.3.3.pre.rc17 → 7.3.4.pre.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/CHANGES.txt +10 -0
- data/lib/splitclient-rb/cache/adapters/redis_adapter.rb +1 -1
- data/lib/splitclient-rb/constants.rb +1 -0
- data/lib/splitclient-rb/engine/push_manager.rb +0 -4
- data/lib/splitclient-rb/engine/sync_manager.rb +61 -47
- data/lib/splitclient-rb/helpers/thread_helper.rb +0 -2
- data/lib/splitclient-rb/split_factory.rb +59 -20
- data/lib/splitclient-rb/sse/event_source/client.rb +31 -30
- data/lib/splitclient-rb/sse/notification_manager_keeper.rb +11 -18
- data/lib/splitclient-rb/sse/sse_handler.rb +10 -39
- data/lib/splitclient-rb/sse/workers/segments_worker.rb +0 -5
- data/lib/splitclient-rb/sse/workers/splits_worker.rb +0 -10
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9eb6c3418573d7fcb02a90e7c597514599f0d1d40c9ee7857383d003475d804
|
4
|
+
data.tar.gz: ef240db401b7f2bfdfecce65eb83e00b18589fc5a6b835fcbfd6ed9d87bbeec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb21d546754ba77427b8ee23bd8d2328039ed6c1f42dfffb0a2a1322ac19b7f967adb0ddf318f23e895d42781de9397a91161d9fe1ab6040c413cdc76cc1859
|
7
|
+
data.tar.gz: 8ada12b1234341b654a81fd7201a2f9b1c0adc9cd2be76affebbeb997186cc67404fa6df00f337945953a1a5140a0bca61c805b060bab80cf35e4a332b31f44e
|
data/.rubocop.yml
CHANGED
@@ -10,6 +10,7 @@ Metrics/MethodLength:
|
|
10
10
|
Max: 20
|
11
11
|
Exclude:
|
12
12
|
- lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb
|
13
|
+
- lib/splitclient-rb/engine/sync_manager.rb
|
13
14
|
|
14
15
|
Metrics/ClassLength:
|
15
16
|
Max: 150
|
@@ -17,9 +18,10 @@ Metrics/ClassLength:
|
|
17
18
|
- lib/splitclient-rb/telemetry/memory/memory_synchronizer.rb
|
18
19
|
|
19
20
|
Metrics/CyclomaticComplexity:
|
20
|
-
Max:
|
21
|
+
Max: 11
|
21
22
|
|
22
23
|
Metrics/ParameterLists:
|
24
|
+
Max: 8
|
23
25
|
Exclude:
|
24
26
|
- lib/splitclient-rb/engine/sync_manager.rb
|
25
27
|
|
@@ -32,6 +34,7 @@ Metrics/LineLength:
|
|
32
34
|
- spec/engine/auth_api_client_spec.rb
|
33
35
|
- spec/telemetry/synchronizer_spec.rb
|
34
36
|
- spec/splitclient/split_config_spec.rb
|
37
|
+
- spec/engine/push_manager_spec.rb
|
35
38
|
|
36
39
|
Style/BracesAroundHashParameters:
|
37
40
|
Exclude:
|
@@ -65,3 +68,4 @@ AllCops:
|
|
65
68
|
- spec/telemetry/synchronizer_spec.rb
|
66
69
|
- lib/splitclient-rb/engine/synchronizer.rb
|
67
70
|
- tmp/**/*
|
71
|
+
- lib/splitclient-rb/sse/event_source/client.rb
|
data/CHANGES.txt
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
CHANGES
|
2
2
|
|
3
|
+
7.3.3 (Jan 28, 2021)
|
4
|
+
- Fixed edge cases where the sdk lost streaming connection.
|
5
|
+
- Updated default auth service url to https://auth.split.io/api/v2/auth
|
6
|
+
- Updated dependencies:
|
7
|
+
- faraday to >= 0.8, < 2.0
|
8
|
+
- net-http-persistent to >= 2.9, < 5.0
|
9
|
+
- redis to >= 4.0.0, < 5.0
|
10
|
+
- socketry to >= 0.4, < 1.0
|
11
|
+
- thread_safe to ~> 0.3
|
12
|
+
|
3
13
|
7.3.2 (Dec 10, 2021)
|
4
14
|
- Updated the readiness flow to be more consistent with the other sdks and improve the readiness time.
|
5
15
|
- Updated the name of telemety key latencies in Redis.
|
@@ -34,7 +34,6 @@ module SplitIoClient
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def stop_sse
|
37
|
-
@config.logger.error('## STOP SSE')
|
38
37
|
@sse_handler.stop
|
39
38
|
SplitIoClient::Helpers::ThreadHelper.stop(:schedule_next_token_refresh, @config)
|
40
39
|
end
|
@@ -47,12 +46,9 @@ module SplitIoClient
|
|
47
46
|
@config.logger.debug("schedule_next_token_refresh refresh in #{time} seconds.") if @config.debug_enabled
|
48
47
|
sleep(time)
|
49
48
|
@config.logger.debug('schedule_next_token_refresh starting ...') if @config.debug_enabled
|
50
|
-
@config.logger.error('## SCHEDULE NEXT TOKEN')
|
51
|
-
|
52
49
|
@sse_handler.stop
|
53
50
|
start_sse
|
54
51
|
rescue StandardError => e
|
55
|
-
@config.logger.error("## SCHEDULE EXCEPTION #{e.inspect}")
|
56
52
|
@config.logger.debug("schedule_next_token_refresh error: #{e.inspect}") if @config.debug_enabled
|
57
53
|
end
|
58
54
|
end
|
@@ -6,35 +6,23 @@ module SplitIoClient
|
|
6
6
|
SYNC_MODE_STREAMING = 0
|
7
7
|
SYNC_MODE_POLLING = 1
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
)
|
18
|
-
@synchronizer = synchronizer
|
19
|
-
notification_manager_keeper = SSE::NotificationManagerKeeper.new(config, telemetry_runtime_producer) do |manager|
|
20
|
-
manager.on_action { |action| process_action(action) }
|
21
|
-
end
|
22
|
-
@sse_handler = SSE::SSEHandler.new(
|
23
|
-
{ config: config, api_key: api_key },
|
24
|
-
@synchronizer,
|
25
|
-
repositories,
|
26
|
-
notification_manager_keeper,
|
27
|
-
telemetry_runtime_producer
|
28
|
-
) do |handler|
|
29
|
-
handler.on_action { |action| process_action(action) }
|
30
|
-
end
|
31
|
-
|
32
|
-
@push_manager = PushManager.new(config, @sse_handler, api_key, telemetry_runtime_producer)
|
33
|
-
@sse_connected = Concurrent::AtomicBoolean.new(false)
|
9
|
+
def initialize(config,
|
10
|
+
synchronizer,
|
11
|
+
telemetry_runtime_producer,
|
12
|
+
telemetry_synchronizer,
|
13
|
+
status_manager,
|
14
|
+
sse_handler,
|
15
|
+
push_manager,
|
16
|
+
status_queue)
|
34
17
|
@config = config
|
18
|
+
@synchronizer = synchronizer
|
35
19
|
@telemetry_runtime_producer = telemetry_runtime_producer
|
36
20
|
@telemetry_synchronizer = telemetry_synchronizer
|
37
21
|
@status_manager = status_manager
|
22
|
+
@sse_handler = sse_handler
|
23
|
+
@push_manager = push_manager
|
24
|
+
@status_queue = status_queue
|
25
|
+
@sse_connected = Concurrent::AtomicBoolean.new(false)
|
38
26
|
end
|
39
27
|
|
40
28
|
def start
|
@@ -55,6 +43,7 @@ module SplitIoClient
|
|
55
43
|
|
56
44
|
if @config.streaming_enabled
|
57
45
|
@config.logger.debug('Starting Straming mode ...')
|
46
|
+
start_push_status_monitor
|
58
47
|
connected = @push_manager.start_sse
|
59
48
|
end
|
60
49
|
|
@@ -66,28 +55,6 @@ module SplitIoClient
|
|
66
55
|
end
|
67
56
|
end
|
68
57
|
|
69
|
-
def process_action(action)
|
70
|
-
@config.logger.error("process_action #{action}")
|
71
|
-
case action
|
72
|
-
when Constants::PUSH_CONNECTED
|
73
|
-
process_connected
|
74
|
-
when Constants::PUSH_RETRYABLE_ERROR
|
75
|
-
process_disconnect(true)
|
76
|
-
when Constants::PUSH_NONRETRYABLE_ERROR
|
77
|
-
process_disconnect(false)
|
78
|
-
when Constants::PUSH_SUBSYSTEM_DOWN
|
79
|
-
process_subsystem_down
|
80
|
-
when Constants::PUSH_SUBSYSTEM_READY
|
81
|
-
process_subsystem_ready
|
82
|
-
when Constants::PUSH_SUBSYSTEM_OFF
|
83
|
-
process_push_shutdown
|
84
|
-
else
|
85
|
-
@config.logger.debug('Incorrect action type.')
|
86
|
-
end
|
87
|
-
rescue StandardError => e
|
88
|
-
@config.logger.error("process_action error: #{e.inspect}")
|
89
|
-
end
|
90
|
-
|
91
58
|
def process_subsystem_ready
|
92
59
|
@synchronizer.stop_periodic_fetch
|
93
60
|
@synchronizer.sync_all
|
@@ -125,6 +92,19 @@ module SplitIoClient
|
|
125
92
|
@config.logger.error("process_connected error: #{e.inspect}")
|
126
93
|
end
|
127
94
|
|
95
|
+
def process_forced_stop
|
96
|
+
unless @sse_connected.value
|
97
|
+
@config.logger.debug('Streaming already disconnected.')
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
@sse_connected.make_false
|
102
|
+
@synchronizer.start_periodic_fetch
|
103
|
+
record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
|
104
|
+
rescue StandardError => e
|
105
|
+
@config.logger.error("process_connected error: #{e.inspect}")
|
106
|
+
end
|
107
|
+
|
128
108
|
def process_disconnect(reconnect)
|
129
109
|
unless @sse_connected.value
|
130
110
|
@config.logger.debug('Streaming already disconnected.')
|
@@ -148,6 +128,40 @@ module SplitIoClient
|
|
148
128
|
def record_telemetry(type, data)
|
149
129
|
@telemetry_runtime_producer.record_streaming_event(type, data)
|
150
130
|
end
|
131
|
+
|
132
|
+
def start_push_status_monitor
|
133
|
+
@config.threads[:push_status_handler] = Thread.new do
|
134
|
+
@config.logger.debug('Starting push status handler ...') if @config.debug_enabled
|
135
|
+
incoming_push_status_handler
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def incoming_push_status_handler
|
140
|
+
while (status = @status_queue.pop)
|
141
|
+
@config.logger.debug("Push status handler dequeue #{status}") if @config.debug_enabled
|
142
|
+
|
143
|
+
case status
|
144
|
+
when Constants::PUSH_CONNECTED
|
145
|
+
process_connected
|
146
|
+
when Constants::PUSH_RETRYABLE_ERROR
|
147
|
+
process_disconnect(true)
|
148
|
+
when Constants::PUSH_FORCED_STOP
|
149
|
+
process_forced_stop
|
150
|
+
when Constants::PUSH_NONRETRYABLE_ERROR
|
151
|
+
process_disconnect(false)
|
152
|
+
when Constants::PUSH_SUBSYSTEM_DOWN
|
153
|
+
process_subsystem_down
|
154
|
+
when Constants::PUSH_SUBSYSTEM_READY
|
155
|
+
process_subsystem_ready
|
156
|
+
when Constants::PUSH_SUBSYSTEM_OFF
|
157
|
+
process_push_shutdown
|
158
|
+
else
|
159
|
+
@config.logger.debug('Incorrect push status type.')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
rescue StandardError => e
|
163
|
+
@config.logger.error("Push status handler error: #{e.inspect}")
|
164
|
+
end
|
151
165
|
end
|
152
166
|
end
|
153
167
|
end
|
@@ -8,11 +8,9 @@ module SplitIoClient
|
|
8
8
|
|
9
9
|
unless thread.nil?
|
10
10
|
config.logger.debug("Stopping #{thread_sym} thread...") if config.debug_enabled
|
11
|
-
# sleep(0.1) while thread.status == 'run'
|
12
11
|
Thread.kill(thread)
|
13
12
|
end
|
14
13
|
rescue StandardError => e
|
15
|
-
puts e.inspect
|
16
14
|
config.logger.error(e.inspect)
|
17
15
|
end
|
18
16
|
|
@@ -33,15 +33,10 @@ module SplitIoClient
|
|
33
33
|
register_factory
|
34
34
|
|
35
35
|
build_telemetry_components
|
36
|
+
build_repositories
|
37
|
+
build_impressions_components
|
38
|
+
build_telemetry_synchronizer
|
36
39
|
|
37
|
-
@splits_repository = SplitsRepository.new(@config)
|
38
|
-
@segments_repository = SegmentsRepository.new(@config)
|
39
|
-
@impressions_repository = ImpressionsRepository.new(@config)
|
40
|
-
@events_repository = EventsRepository.new(@config, @api_key, @runtime_producer)
|
41
|
-
@impression_counter = SplitIoClient::Engine::Common::ImpressionCounter.new
|
42
|
-
@impressions_manager = SplitIoClient::Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer)
|
43
|
-
@telemetry_api = SplitIoClient::Api::TelemetryApi.new(@config, @api_key, @runtime_producer)
|
44
|
-
@telemetry_synchronizer = Telemetry::Synchronizer.new(@config, @telemetry_consumers, @init_producer, repositories, @telemetry_api)
|
45
40
|
@status_manager = Engine::StatusManager.new(@config)
|
46
41
|
|
47
42
|
start!
|
@@ -59,18 +54,12 @@ module SplitIoClient
|
|
59
54
|
return
|
60
55
|
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
segment_fetcher: segment_fetcher,
|
67
|
-
imp_counter: @impression_counter,
|
68
|
-
telemetry_runtime_producer: @runtime_producer,
|
69
|
-
telemetry_synchronizer: @telemetry_synchronizer
|
70
|
-
}
|
57
|
+
build_fetchers
|
58
|
+
build_synchronizer
|
59
|
+
build_streaming_components
|
60
|
+
build_sync_manager
|
71
61
|
|
72
|
-
|
73
|
-
SplitIoClient::Engine::SyncManager.new(repositories, @api_key, @config, synchronizer, @runtime_producer, @telemetry_synchronizer, @status_manager).start
|
62
|
+
@sync_manager.start
|
74
63
|
end
|
75
64
|
|
76
65
|
def stop!
|
@@ -166,6 +155,56 @@ module SplitIoClient
|
|
166
155
|
@runtime_producer = Telemetry::RuntimeProducer.new(@config)
|
167
156
|
|
168
157
|
@telemetry_consumers = { init: @init_consumer, evaluation: @evaluation_consumer, runtime: @runtime_consumer }
|
169
|
-
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def build_fetchers
|
161
|
+
@split_fetcher = SplitFetcher.new(@splits_repository, @api_key, @config, @runtime_producer)
|
162
|
+
@segment_fetcher = SegmentFetcher.new(@segments_repository, @api_key, @config, @runtime_producer)
|
163
|
+
end
|
164
|
+
|
165
|
+
def build_synchronizer
|
166
|
+
params = {
|
167
|
+
split_fetcher: @split_fetcher,
|
168
|
+
segment_fetcher: @segment_fetcher,
|
169
|
+
imp_counter: @impression_counter,
|
170
|
+
telemetry_runtime_producer: @runtime_producer,
|
171
|
+
telemetry_synchronizer: @telemetry_synchronizer
|
172
|
+
}
|
173
|
+
|
174
|
+
@synchronizer = Engine::Synchronizer.new(repositories, @api_key, @config, params)
|
175
|
+
end
|
176
|
+
|
177
|
+
def build_streaming_components
|
178
|
+
@push_status_queue = Queue.new
|
179
|
+
splits_worker = SSE::Workers::SplitsWorker.new(@synchronizer, @config, @splits_repository)
|
180
|
+
segments_worker = SSE::Workers::SegmentsWorker.new(@synchronizer, @config, @segments_repository)
|
181
|
+
notification_manager_keeper = SSE::NotificationManagerKeeper.new(@config, @runtime_producer, @push_status_queue)
|
182
|
+
notification_processor = SSE::NotificationProcessor.new(@config, splits_worker, segments_worker)
|
183
|
+
event_parser = SSE::EventSource::EventParser.new(config)
|
184
|
+
sse_client = SSE::EventSource::Client.new(@config, @api_key, @runtime_producer, event_parser, notification_manager_keeper, notification_processor, @push_status_queue)
|
185
|
+
@sse_handler = SSE::SSEHandler.new(@config, splits_worker, segments_worker, sse_client)
|
186
|
+
@push_manager = Engine::PushManager.new(@config, @sse_handler, @api_key, @runtime_producer)
|
187
|
+
end
|
188
|
+
|
189
|
+
def build_sync_manager
|
190
|
+
@sync_manager = Engine::SyncManager.new(@config, @synchronizer, @runtime_producer, @telemetry_synchronizer, @status_manager, @sse_handler, @push_manager, @push_status_queue)
|
191
|
+
end
|
192
|
+
|
193
|
+
def build_repositories
|
194
|
+
@splits_repository = SplitsRepository.new(@config)
|
195
|
+
@segments_repository = SegmentsRepository.new(@config)
|
196
|
+
@impressions_repository = ImpressionsRepository.new(@config)
|
197
|
+
@events_repository = EventsRepository.new(@config, @api_key, @runtime_producer)
|
198
|
+
end
|
199
|
+
|
200
|
+
def build_telemetry_synchronizer
|
201
|
+
telemetry_api = Api::TelemetryApi.new(@config, @api_key, @runtime_producer)
|
202
|
+
@telemetry_synchronizer = Telemetry::Synchronizer.new(@config, @telemetry_consumers, @init_producer, repositories, telemetry_api)
|
203
|
+
end
|
204
|
+
|
205
|
+
def build_impressions_components
|
206
|
+
@impression_counter = Engine::Common::ImpressionCounter.new
|
207
|
+
@impressions_manager = Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer)
|
208
|
+
end
|
170
209
|
end
|
171
210
|
end
|
@@ -13,29 +13,28 @@ module SplitIoClient
|
|
13
13
|
KEEP_ALIVE_RESPONSE = "c\r\n:keepalive\n\n\r\n".freeze
|
14
14
|
ERROR_EVENT_TYPE = 'error'.freeze
|
15
15
|
|
16
|
-
def initialize(config,
|
16
|
+
def initialize(config,
|
17
|
+
api_key,
|
18
|
+
telemetry_runtime_producer,
|
19
|
+
event_parser,
|
20
|
+
notification_manager_keeper,
|
21
|
+
notification_processor,
|
22
|
+
status_queue,
|
23
|
+
read_timeout: DEFAULT_READ_TIMEOUT)
|
17
24
|
@config = config
|
25
|
+
@api_key = api_key
|
26
|
+
@telemetry_runtime_producer = telemetry_runtime_producer
|
27
|
+
@event_parser = event_parser
|
28
|
+
@notification_manager_keeper = notification_manager_keeper
|
29
|
+
@notification_processor = notification_processor
|
30
|
+
@status_queue = status_queue
|
18
31
|
@read_timeout = read_timeout
|
19
32
|
@connected = Concurrent::AtomicBoolean.new(false)
|
20
33
|
@first_event = Concurrent::AtomicBoolean.new(true)
|
21
34
|
@socket = nil
|
22
|
-
@event_parser = SSE::EventSource::EventParser.new(config)
|
23
|
-
@on = { event: ->(_) {}, action: ->(_) {} }
|
24
|
-
@api_key = api_key
|
25
|
-
@telemetry_runtime_producer = telemetry_runtime_producer
|
26
|
-
|
27
|
-
yield self if block_given?
|
28
|
-
end
|
29
|
-
|
30
|
-
def on_event(&action)
|
31
|
-
@on[:event] = action
|
32
35
|
end
|
33
36
|
|
34
|
-
def
|
35
|
-
@on[:action] = action
|
36
|
-
end
|
37
|
-
|
38
|
-
def close(action = nil)
|
37
|
+
def close(status = nil)
|
39
38
|
unless connected?
|
40
39
|
@config.logger.error('SSEClient already disconected.') if @config.debug_enabled
|
41
40
|
return
|
@@ -43,8 +42,7 @@ module SplitIoClient
|
|
43
42
|
|
44
43
|
@connected.make_false
|
45
44
|
@socket&.close
|
46
|
-
|
47
|
-
dispatch_action(action) unless action.nil?
|
45
|
+
push_status(status)
|
48
46
|
rescue StandardError => e
|
49
47
|
@config.logger.error("SSEClient close Error: #{e.inspect}")
|
50
48
|
end
|
@@ -76,12 +74,10 @@ module SplitIoClient
|
|
76
74
|
|
77
75
|
def connect_thread(latch)
|
78
76
|
@config.threads[:connect_stream] = Thread.new do
|
79
|
-
@config.logger.error('## CONNECT THREAD')
|
80
77
|
@config.logger.info('Starting connect_stream thread ...') if @config.debug_enabled
|
81
|
-
|
82
|
-
|
78
|
+
new_status = connect_stream(latch)
|
79
|
+
push_status(new_status)
|
83
80
|
@config.logger.info('connect_stream thread finished.') if @config.debug_enabled
|
84
|
-
@config.logger.error('#### DISCONNECTED')
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
@@ -99,6 +95,8 @@ module SplitIoClient
|
|
99
95
|
@config.logger.error(e.inspect)
|
100
96
|
return nil
|
101
97
|
rescue StandardError => e
|
98
|
+
return nil if ENV['SPLITCLIENT_ENV'] == 'test'
|
99
|
+
|
102
100
|
@config.logger.error("Error reading partial data: #{e.inspect}") if @config.debug_enabled
|
103
101
|
return Constants::PUSH_RETRYABLE_ERROR
|
104
102
|
end
|
@@ -133,7 +131,7 @@ module SplitIoClient
|
|
133
131
|
if response_code == OK_CODE && !error_event
|
134
132
|
@connected.make_true
|
135
133
|
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::SSE_CONNECTION_ESTABLISHED, nil)
|
136
|
-
|
134
|
+
push_status(Constants::PUSH_CONNECTED)
|
137
135
|
end
|
138
136
|
|
139
137
|
latch.count_down
|
@@ -189,15 +187,18 @@ module SplitIoClient
|
|
189
187
|
end
|
190
188
|
|
191
189
|
def dispatch_event(event)
|
192
|
-
|
193
|
-
|
190
|
+
if event.occupancy?
|
191
|
+
@notification_manager_keeper.handle_incoming_occupancy_event(event)
|
192
|
+
else
|
193
|
+
@notification_processor.process(event)
|
194
|
+
end
|
194
195
|
end
|
195
196
|
|
196
|
-
def
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
197
|
+
def push_status(status)
|
198
|
+
return if status.nil?
|
199
|
+
|
200
|
+
@config.logger.debug("Pushing new sse status: #{status}")
|
201
|
+
@status_queue.push(status)
|
201
202
|
end
|
202
203
|
end
|
203
204
|
end
|
@@ -9,15 +9,13 @@ module SplitIoClient
|
|
9
9
|
ENABLED = 1
|
10
10
|
PAUSED = 2
|
11
11
|
|
12
|
-
def initialize(config, telemetry_runtime_producer)
|
12
|
+
def initialize(config, telemetry_runtime_producer, status_queue)
|
13
13
|
@config = config
|
14
|
+
@telemetry_runtime_producer = telemetry_runtime_producer
|
15
|
+
@status_queue = status_queue
|
14
16
|
@publisher_available = Concurrent::AtomicBoolean.new(true)
|
15
17
|
@publishers_pri = Concurrent::AtomicFixnum.new
|
16
18
|
@publishers_sec = Concurrent::AtomicFixnum.new
|
17
|
-
@on = { action: ->(_) {} }
|
18
|
-
@telemetry_runtime_producer = telemetry_runtime_producer
|
19
|
-
|
20
|
-
yield self if block_given?
|
21
19
|
end
|
22
20
|
|
23
21
|
def handle_incoming_occupancy_event(event)
|
@@ -27,27 +25,22 @@ module SplitIoClient
|
|
27
25
|
process_event_occupancy(event.channel, event.data['metrics']['publishers'])
|
28
26
|
end
|
29
27
|
rescue StandardError => e
|
30
|
-
p e
|
31
28
|
@config.logger.error(e)
|
32
29
|
end
|
33
30
|
|
34
|
-
def on_action(&action)
|
35
|
-
@on[:action] = action
|
36
|
-
end
|
37
|
-
|
38
31
|
private
|
39
32
|
|
40
33
|
def process_event_control(type)
|
41
34
|
case type
|
42
35
|
when 'STREAMING_PAUSED'
|
43
36
|
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, PAUSED)
|
44
|
-
|
37
|
+
push_status(Constants::PUSH_SUBSYSTEM_DOWN)
|
45
38
|
when 'STREAMING_RESUMED'
|
46
39
|
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, ENABLED)
|
47
|
-
|
40
|
+
push_status(Constants::PUSH_SUBSYSTEM_READY) if @publisher_available.value
|
48
41
|
when 'STREAMING_DISABLED'
|
49
42
|
@telemetry_runtime_producer.record_streaming_event(Telemetry::Domain::Constants::STREAMING_STATUS, DISABLED)
|
50
|
-
|
43
|
+
push_status(Constants::PUSH_SUBSYSTEM_OFF)
|
51
44
|
else
|
52
45
|
@config.logger.error("Incorrect event type: #{incoming_notification}")
|
53
46
|
end
|
@@ -60,10 +53,10 @@ module SplitIoClient
|
|
60
53
|
|
61
54
|
if !are_publishers_available? && @publisher_available.value
|
62
55
|
@publisher_available.make_false
|
63
|
-
|
56
|
+
push_status(Constants::PUSH_SUBSYSTEM_DOWN)
|
64
57
|
elsif are_publishers_available? && !@publisher_available.value
|
65
58
|
@publisher_available.make_true
|
66
|
-
|
59
|
+
push_status(Constants::PUSH_SUBSYSTEM_READY)
|
67
60
|
end
|
68
61
|
end
|
69
62
|
|
@@ -81,9 +74,9 @@ module SplitIoClient
|
|
81
74
|
@publishers_pri.value.positive? || @publishers_sec.value.positive?
|
82
75
|
end
|
83
76
|
|
84
|
-
def
|
85
|
-
@config.logger.debug("
|
86
|
-
@
|
77
|
+
def push_status(status)
|
78
|
+
@config.logger.debug("Pushing occupancy status: #{status}")
|
79
|
+
@status_queue.push(status)
|
87
80
|
end
|
88
81
|
end
|
89
82
|
end
|
@@ -5,33 +5,22 @@ module SplitIoClient
|
|
5
5
|
class SSEHandler
|
6
6
|
attr_reader :sse_client
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, @config, repositories[:segments])
|
17
|
-
@notification_processor = SplitIoClient::SSE::NotificationProcessor.new(@config, @splits_worker, @segments_worker)
|
18
|
-
@sse_client = SSE::EventSource::Client.new(@config, metadata[:api_key], telemetry_runtime_producer) do |client|
|
19
|
-
client.on_event { |event| handle_incoming_message(event) }
|
20
|
-
client.on_action { |action| process_action(action) }
|
21
|
-
end
|
22
|
-
|
23
|
-
@on = { action: ->(_) {} }
|
24
|
-
|
25
|
-
yield self if block_given?
|
8
|
+
def initialize(config,
|
9
|
+
splits_worker,
|
10
|
+
segments_worker,
|
11
|
+
sse_client)
|
12
|
+
@config = config
|
13
|
+
@splits_worker = splits_worker
|
14
|
+
@segments_worker = segments_worker
|
15
|
+
@sse_client = sse_client
|
26
16
|
end
|
27
17
|
|
28
18
|
def start(token_jwt, channels)
|
29
|
-
|
30
|
-
@sse_client.start(url)
|
19
|
+
@sse_client.start("#{@config.streaming_service_url}?channels=#{channels}&v=1.1&accessToken=#{token_jwt}")
|
31
20
|
end
|
32
21
|
|
33
22
|
def stop
|
34
|
-
@sse_client.close(Constants::
|
23
|
+
@sse_client.close(Constants::PUSH_FORCED_STOP)
|
35
24
|
stop_workers
|
36
25
|
rescue StandardError => e
|
37
26
|
@config.logger.debug("SSEHandler stop error: #{e.inspect}") if @config.debug_enabled
|
@@ -50,24 +39,6 @@ module SplitIoClient
|
|
50
39
|
@splits_worker.stop
|
51
40
|
@segments_worker.stop
|
52
41
|
end
|
53
|
-
|
54
|
-
def on_action(&action)
|
55
|
-
@on[:action] = action
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def process_action(action)
|
61
|
-
@on[:action].call(action)
|
62
|
-
end
|
63
|
-
|
64
|
-
def handle_incoming_message(notification)
|
65
|
-
if notification.occupancy?
|
66
|
-
@notification_manager_keeper.handle_incoming_occupancy_event(notification)
|
67
|
-
else
|
68
|
-
@notification_processor.process(notification)
|
69
|
-
end
|
70
|
-
end
|
71
42
|
end
|
72
43
|
end
|
73
44
|
end
|
@@ -13,11 +13,6 @@ module SplitIoClient
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def add_to_queue(change_number, segment_name)
|
16
|
-
unless @running.value
|
17
|
-
@config.logger.debug('segments worker not running.')
|
18
|
-
return
|
19
|
-
end
|
20
|
-
|
21
16
|
item = { change_number: change_number, segment_name: segment_name }
|
22
17
|
@config.logger.debug("SegmentsWorker add to queue #{item}")
|
23
18
|
@queue.push(item)
|
@@ -33,21 +33,11 @@ module SplitIoClient
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def add_to_queue(change_number)
|
36
|
-
unless @running.value
|
37
|
-
@config.logger.debug('splits worker not running.')
|
38
|
-
return
|
39
|
-
end
|
40
|
-
|
41
36
|
@config.logger.debug("SplitsWorker add to queue #{change_number}")
|
42
37
|
@queue.push(change_number)
|
43
38
|
end
|
44
39
|
|
45
40
|
def kill_split(change_number, split_name, default_treatment)
|
46
|
-
unless @running.value
|
47
|
-
@config.logger.debug('splits worker not running.')
|
48
|
-
return
|
49
|
-
end
|
50
|
-
|
51
41
|
return if @splits_repository.get_change_number.to_i > change_number
|
52
42
|
|
53
43
|
@config.logger.debug("SplitsWorker kill #{split_name}, #{change_number}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splitclient-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.3.
|
4
|
+
version: 7.3.4.pre.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Split Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: allocation_stats
|