splitclient-rb 7.1.0.pre.rc4 → 7.1.0.pre.rc5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69fe751aec852ee524d59e0bddc36cb39454d7633a950590e15eb277fb113aa1
4
- data.tar.gz: 9c5bbaaa6667ff765de75cdf898512b345b109a48a59d5bff95217e51291ad57
3
+ metadata.gz: 587be9d9556ccffe349a951df016d93c080db62548b1506a18794b726984a92b
4
+ data.tar.gz: 919deabf86f1a5af72b3ace1ecf55c115eddd03517c40c8f4ff8d55e33bad7e8
5
5
  SHA512:
6
- metadata.gz: 9d7778f0ee964578d877cb48b58b7f3f42153a68c9cb5a69b816cc78d5e9bf16059486819b157e667c5c58d31d6c7008cd1fe230f003c4e8945de468ada16fc8
7
- data.tar.gz: d0aac080888d6364af6dc4672e7911095afbe30e9bbed43fd17ec6c7f6d0b76c64a4f5548701e3dc8b50732e7b70584760f7fd132b8d91e2def8ac0d7eb70862
6
+ metadata.gz: 28338bed37a658a9c19e474dd4ba3253ad1a1632cf18e547cd2596d36454eb32d2e141002a310fb383fec06d443b10b6b9cdc61865cc4069d5e1834ea0b492c7
7
+ data.tar.gz: 7dbeb3f36bed2a8d632173fd1264475aef011c591be2c5b5f89d3a1446a4b64bde1331e14f09f62bcc386852be51f1141dfc69452d7faecb66c48928d652fa1c
data/.rubocop.yml CHANGED
@@ -15,6 +15,12 @@ Metrics/LineLength:
15
15
  Exclude:
16
16
  - spec/sse/**/*
17
17
  - spec/integrations/**/*
18
+ - spec/engine/sync_manager_spec.rb
19
+
20
+ Style/BracesAroundHashParameters:
21
+ Exclude:
22
+ - spec/integrations/push_client_spec.rb
23
+ - spec/engine/synchronizer_spec.rb
18
24
 
19
25
  Metrics/BlockLength:
20
26
  Exclude:
@@ -28,9 +28,13 @@ module SplitIoClient
28
28
  end
29
29
 
30
30
  def fetch_segment(name)
31
- @semaphore.synchronize { segments_api.fetch_segments_by_names([name]) }
31
+ @semaphore.synchronize do
32
+ segments_api.fetch_segments_by_names([name])
33
+ true
34
+ end
32
35
  rescue StandardError => error
33
36
  @config.log_found_exception(__method__.to_s, error)
37
+ false
34
38
  end
35
39
 
36
40
  def fetch_segments
@@ -51,7 +55,7 @@ module SplitIoClient
51
55
 
52
56
  def segments_thread
53
57
  @config.threads[:segment_fetcher] = Thread.new do
54
- @config.logger.info('Starting segments fetcher service')
58
+ @config.logger.info('Starting segments fetcher service') if @config.debug_enabled
55
59
 
56
60
  loop do
57
61
  next unless @sdk_blocker.splits_repository.ready?
@@ -41,9 +41,11 @@ module SplitIoClient
41
41
  @config.logger.debug("segments seen(#{data[:segment_names].length}): #{data[:segment_names].to_a}") if @config.debug_enabled
42
42
 
43
43
  @sdk_blocker.splits_ready!
44
+ true
44
45
  end
45
46
  rescue StandardError => error
46
47
  @config.log_found_exception(__method__.to_s, error)
48
+ false
47
49
  end
48
50
 
49
51
  def stop_splits_thread
@@ -54,7 +56,7 @@ module SplitIoClient
54
56
 
55
57
  def splits_thread
56
58
  @config.threads[:split_fetcher] = Thread.new do
57
- @config.logger.info('Starting splits fetcher service')
59
+ @config.logger.info('Starting splits fetcher service') if @config.debug_enabled
58
60
  loop do
59
61
  fetch_splits
60
62
 
@@ -5,5 +5,6 @@ class SplitIoClient::Constants
5
5
  CONTROL_PRI = 'control_pri'
6
6
  CONTROL_SEC = 'control_sec'
7
7
  OCCUPANCY_CHANNEL_PREFIX = '[?occupancy=metrics.publishers]'
8
+ FETCH_BACK_OFF_BASE_RETRIES = 1
8
9
  end
9
10
 
@@ -41,7 +41,7 @@ module SplitIoClient
41
41
  channels_hash = JSON.parse(capability)
42
42
  channels_string = channels_hash.keys.join(',')
43
43
  channels_string = control_channels(channels_string)
44
- @config.logger.debug("Channels #{channels_string}")
44
+ @config.logger.debug("Channels #{channels_string}") if @config.debug_enabled
45
45
  CGI.escape(channels_string)
46
46
  end
47
47
 
@@ -50,7 +50,7 @@ module SplitIoClient
50
50
  end
51
51
 
52
52
  def process_success(response)
53
- @config.logger.debug("Success connection to: #{@config.auth_service_url}")
53
+ @config.logger.debug("Success connection to: #{@config.auth_service_url}") if @config.debug_enabled
54
54
 
55
55
  body_json = JSON.parse(response.body, symbolize_names: true)
56
56
  push_enabled = body_json[:pushEnabled]
@@ -8,13 +8,13 @@ module SplitIoClient
8
8
  @sse_handler = sse_handler
9
9
  @auth_api_client = AuthApiClient.new(@config)
10
10
  @api_key = api_key
11
- @back_off = SplitIoClient::SSE::EventSource::BackOff.new(@config.auth_retry_back_off_base)
11
+ @back_off = SplitIoClient::SSE::EventSource::BackOff.new(@config.auth_retry_back_off_base, 1)
12
12
  end
13
13
 
14
14
  def start_sse
15
15
  response = @auth_api_client.authenticate(@api_key)
16
16
 
17
- @config.logger.debug("Auth service response push_enabled: #{response[:push_enabled]}")
17
+ @config.logger.debug("Auth service response push_enabled: #{response[:push_enabled]}") if @config.debug_enabled
18
18
  if response[:push_enabled]
19
19
  @sse_handler.start(response[:token], response[:channels])
20
20
  schedule_next_token_refresh(response[:exp])
@@ -59,7 +59,7 @@ module SplitIoClient
59
59
  @synchronizer.start_periodic_fetch
60
60
  @synchronizer.start_periodic_data_recording
61
61
  rescue StandardError => e
62
- @config.logger.error(e)
62
+ @config.logger.error("start_poll error : #{e.inspect}")
63
63
  end
64
64
 
65
65
  # Starts thread which fetch splits and segments once and trigger task to periodic data recording.
@@ -69,7 +69,7 @@ module SplitIoClient
69
69
  @synchronizer.sync_all
70
70
  @synchronizer.start_periodic_data_recording
71
71
  rescue StandardError => e
72
- @config.logger.error(e)
72
+ @config.logger.error("stream_start_thread error : #{e.inspect}")
73
73
  end
74
74
  end
75
75
  end
@@ -80,7 +80,7 @@ module SplitIoClient
80
80
  begin
81
81
  @push_manager.start_sse
82
82
  rescue StandardError => e
83
- @config.logger.error(e)
83
+ @config.logger.error("stream_start_sse_thread error : #{e.inspect}")
84
84
  end
85
85
  end
86
86
  end
@@ -97,24 +97,29 @@ module SplitIoClient
97
97
  @synchronizer.stop_periodic_fetch
98
98
  @synchronizer.sync_all
99
99
  @sse_handler.start_workers
100
+ rescue StandardError => e
101
+ @config.logger.error("process_connected error: #{e.inspect}")
100
102
  end
101
103
 
102
104
  def process_disconnect
103
105
  @sse_handler.stop_workers
104
106
  @synchronizer.start_periodic_fetch
107
+ rescue StandardError => e
108
+ @config.logger.error("process_disconnect error: #{e.inspect}")
105
109
  end
106
110
 
107
111
  def process_occupancy(push_enable)
108
112
  process_disconnect unless push_enable
109
113
  process_connected if push_enable
114
+ rescue StandardError => e
115
+ @config.logger.error("process_occupancy error: #{e.inspect}")
110
116
  end
111
117
 
112
118
  def process_push_shutdown
113
- @sse_handler.stop_workers
114
119
  @push_manager.stop_sse
115
- start_poll
120
+ process_disconnect
116
121
  rescue StandardError => e
117
- @config.logger.error(e)
122
+ @config.logger.error("process_push_shutdown error: #{e.inspect}")
118
123
  end
119
124
  end
120
125
  end
@@ -26,7 +26,7 @@ module SplitIoClient
26
26
  end
27
27
 
28
28
  def sync_all
29
- @config.logger.debug('Synchronizing Splits and Segments ...')
29
+ @config.logger.debug('Synchronizing Splits and Segments ...') if @config.debug_enabled
30
30
  fetch_splits
31
31
  fetch_segments
32
32
  end
@@ -48,11 +48,21 @@ module SplitIoClient
48
48
  end
49
49
 
50
50
  def fetch_splits
51
- @split_fetcher.fetch_splits
51
+ back_off = SplitIoClient::SSE::EventSource::BackOff.new(SplitIoClient::Constants::FETCH_BACK_OFF_BASE_RETRIES, 1)
52
+ loop do
53
+ break if @split_fetcher.fetch_splits
54
+
55
+ sleep(back_off.interval)
56
+ end
52
57
  end
53
58
 
54
59
  def fetch_segment(name)
55
- @segment_fetcher.fetch_segment(name)
60
+ back_off = SplitIoClient::SSE::EventSource::BackOff.new(SplitIoClient::Constants::FETCH_BACK_OFF_BASE_RETRIES, 1)
61
+ loop do
62
+ break if @segment_fetcher.fetch_segment(name)
63
+
64
+ sleep(back_off.interval)
65
+ end
56
66
  end
57
67
 
58
68
  private
@@ -7,12 +7,18 @@ module SplitIoClient
7
7
  thread = config.threads[thread_sym]
8
8
 
9
9
  unless thread.nil?
10
- config.logger.debug("Stopping #{thread_sym} ...")
10
+ config.logger.debug("Stopping #{thread_sym} ...") if config.debug_enabled
11
11
  sleep(0.1) while thread.status == 'run'
12
12
  Thread.kill(thread)
13
13
  end
14
- rescue StandardError => error
15
- config.logger.error(error.inspect)
14
+ rescue StandardError => e
15
+ config.logger.error(e.inspect)
16
+ end
17
+
18
+ def self.alive?(thread_sym, config)
19
+ thread = config.threads[thread_sym]
20
+
21
+ thread.nil? ? false : thread.alive?
16
22
  end
17
23
  end
18
24
  end
@@ -4,8 +4,8 @@ module SplitIoClient
4
4
  module SSE
5
5
  module EventSource
6
6
  class BackOff
7
- def initialize(back_off_base)
8
- @attempt = 0
7
+ def initialize(back_off_base, attempt = 0)
8
+ @attempt = attempt
9
9
  @back_off_base = back_off_base
10
10
  end
11
11
 
@@ -64,7 +64,7 @@ module SplitIoClient
64
64
  interval = @back_off.interval
65
65
  sleep(interval) if interval.positive?
66
66
 
67
- @config.logger.info("Connecting to #{@uri.host}...")
67
+ @config.logger.info("Connecting to #{@uri.host}...") if @config.debug_enabled
68
68
 
69
69
  socket_write
70
70
 
@@ -72,7 +72,13 @@ module SplitIoClient
72
72
  begin
73
73
  partial_data = @socket.readpartial(2048, timeout: @read_timeout)
74
74
  rescue Socketry::TimeoutError
75
- @config.logger.error("Socket read time out in #{@read_timeout} seconds")
75
+ @config.logger.error("Socket read time out in #{@read_timeout} seconds") if @config.debug_enabled
76
+ @connected.make_false
77
+ @socket&.close
78
+ @socket = nil
79
+ connect_stream
80
+ rescue StandardError => e
81
+ @config.logger.error(e.inspect)
76
82
  close
77
83
  connect_stream
78
84
  end
@@ -98,7 +104,7 @@ module SplitIoClient
98
104
 
99
105
  def process_data(partial_data)
100
106
  unless partial_data.nil? || partial_data == KEEP_ALIVE_RESPONSE
101
- @config.logger.debug("Event partial data: #{partial_data}")
107
+ @config.logger.debug("Event partial data: #{partial_data}") if @config.debug_enabled
102
108
  buffer = read_partial_data(partial_data)
103
109
  events = parse_event(buffer)
104
110
 
@@ -113,7 +119,7 @@ module SplitIoClient
113
119
  req << "Host: #{uri.host}\r\n"
114
120
  req << "Accept: text/event-stream\r\n"
115
121
  req << "Cache-Control: no-cache\r\n\r\n"
116
- @config.logger.debug("Request info: #{req}")
122
+ @config.logger.debug("Request info: #{req}") if @config.debug_enabled
117
123
  req
118
124
  end
119
125
 
@@ -142,6 +148,7 @@ module SplitIoClient
142
148
 
143
149
  events
144
150
  rescue StandardError => e
151
+ @config.logger.debug(buffer)
145
152
  @config.logger.error("Error during parsing a event: #{e.inspect}")
146
153
  []
147
154
  end
@@ -160,7 +167,7 @@ module SplitIoClient
160
167
  events.each do |event|
161
168
  raise SSEClientException.new(event), 'Error event' if event.event_type == 'error'
162
169
 
163
- @config.logger.debug("Dispatching event: #{event.event_type}, #{event.channel}")
170
+ @config.logger.debug("Dispatching event: #{event.event_type}, #{event.channel}") if @config.debug_enabled
164
171
  @on[:event].call(event)
165
172
  end
166
173
  rescue SSEClientException => e
@@ -171,12 +178,12 @@ module SplitIoClient
171
178
  def dispatch_connected
172
179
  @connected.make_true
173
180
  @back_off.reset
174
- @config.logger.debug('Dispatching connected')
181
+ @config.logger.debug('Dispatching connected') if @config.debug_enabled
175
182
  @on[:connected].call
176
183
  end
177
184
 
178
185
  def dispatch_disconnect
179
- @config.logger.debug('Dispatching disconnect')
186
+ @config.logger.debug('Dispatching disconnect') if @config.debug_enabled
180
187
  @on[:disconnect].call
181
188
  end
182
189
  end
@@ -47,9 +47,7 @@ module SplitIoClient
47
47
  end
48
48
 
49
49
  def process_event_occupancy(publishers)
50
- @config.logger.debug(
51
- "Occupancy process event with #{publishers} publishers and polling on: #{@publisher_available.value}"
52
- )
50
+ @config.logger.debug("Occupancy process event with #{publishers} publishers") if @config.debug_enabled
53
51
  if publishers <= 0 && @publisher_available.value
54
52
  @publisher_available.make_false
55
53
  dispatch_occupancy_event(false)
@@ -25,12 +25,12 @@ module SplitIoClient
25
25
  private
26
26
 
27
27
  def process_split_update(notification)
28
- @config.logger.debug("SPLIT UPDATE notification received: #{notification}")
28
+ @config.logger.debug("SPLIT UPDATE notification received: #{notification}") if @config.debug_enabled
29
29
  @splits_worker.add_to_queue(notification.data['changeNumber'])
30
30
  end
31
31
 
32
32
  def process_split_kill(notification)
33
- @config.logger.debug("SPLIT KILL notification received: #{notification}")
33
+ @config.logger.debug("SPLIT KILL notification received: #{notification}") if @config.debug_enabled
34
34
  change_number = notification.data['changeNumber']
35
35
  default_treatment = notification.data['defaultTreatment']
36
36
  split_name = notification.data['splitName']
@@ -39,7 +39,7 @@ module SplitIoClient
39
39
  end
40
40
 
41
41
  def process_segment_update(notification)
42
- @config.logger.debug("SEGMENT UPDATE notification received: #{notification}")
42
+ @config.logger.debug("SEGMENT UPDATE notification received: #{notification}") if @config.debug_enabled
43
43
  change_number = notification.data['changeNumber']
44
44
  segment_name = notification.data['segmentName']
45
45
 
@@ -10,7 +10,6 @@ module SplitIoClient
10
10
  @notification_manager_keeper = notification_manager_keeper
11
11
  @splits_worker = SplitIoClient::SSE::Workers::SplitsWorker.new(synchronizer, config, splits_repository)
12
12
  @segments_worker = SplitIoClient::SSE::Workers::SegmentsWorker.new(synchronizer, config, segments_repository)
13
- @control_worker = SplitIoClient::SSE::Workers::ControlWorker.new(config)
14
13
  @notification_processor = SplitIoClient::SSE::NotificationProcessor.new(config, @splits_worker, @segments_worker)
15
14
 
16
15
  @on = { connected: ->(_) {}, disconnect: ->(_) {} }
@@ -40,13 +39,11 @@ module SplitIoClient
40
39
  def start_workers
41
40
  @splits_worker.start
42
41
  @segments_worker.start
43
- @control_worker.start
44
42
  end
45
43
 
46
44
  def stop_workers
47
45
  @splits_worker.stop
48
46
  @segments_worker.stop
49
- @control_worker.stop
50
47
  end
51
48
 
52
49
  def on_connected(&action)
@@ -8,15 +8,20 @@ module SplitIoClient
8
8
  @synchronizer = synchronizer
9
9
  @config = config
10
10
  @segments_repository = segments_repository
11
- @queue = Queue.new
11
+ @queue = nil
12
12
  end
13
13
 
14
14
  def start
15
+ return if SplitIoClient::Helpers::ThreadHelper.alive?(:segment_update_worker, @config)
16
+
17
+ @queue = Queue.new
15
18
  perform_thread
16
19
  perform_passenger_forked if defined?(PhusionPassenger)
17
20
  end
18
21
 
19
22
  def add_to_queue(change_number, segment_name)
23
+ return if @queue.nil?
24
+
20
25
  item = { change_number: change_number, segment_name: segment_name }
21
26
  @config.logger.debug("SegmentsWorker add to queue #{item}")
22
27
  @queue.push(item)
@@ -24,6 +29,7 @@ module SplitIoClient
24
29
 
25
30
  def stop
26
31
  SplitIoClient::Helpers::ThreadHelper.stop(:segment_update_worker, @config)
32
+ @queue = nil
27
33
  end
28
34
 
29
35
  private
@@ -43,7 +49,7 @@ module SplitIoClient
43
49
 
44
50
  def perform_thread
45
51
  @config.threads[:segment_update_worker] = Thread.new do
46
- @config.logger.debug('Starting segments worker ...')
52
+ @config.logger.debug('Starting segments worker ...') if @config.debug_enabled
47
53
  perform
48
54
  end
49
55
  end
@@ -8,20 +8,26 @@ module SplitIoClient
8
8
  @synchronizer = synchronizer
9
9
  @config = config
10
10
  @splits_repository = splits_repository
11
- @queue = Queue.new
12
11
  end
13
12
 
14
13
  def start
14
+ return if SplitIoClient::Helpers::ThreadHelper.alive?(:split_update_worker, @config)
15
+
16
+ @queue = Queue.new
15
17
  perform_thread
16
18
  perform_passenger_forked if defined?(PhusionPassenger)
17
19
  end
18
20
 
19
21
  def add_to_queue(change_number)
22
+ return if @queue.nil?
23
+
20
24
  @config.logger.debug("SplitsWorker add to queue #{change_number}")
21
25
  @queue.push(change_number)
22
26
  end
23
27
 
24
28
  def kill_split(change_number, split_name, default_treatment)
29
+ return if @queue.nil?
30
+
25
31
  @config.logger.debug("SplitsWorker kill #{split_name}, #{change_number}")
26
32
  @splits_repository.kill(change_number, split_name, default_treatment)
27
33
  add_to_queue(change_number)
@@ -29,6 +35,7 @@ module SplitIoClient
29
35
 
30
36
  def stop
31
37
  SplitIoClient::Helpers::ThreadHelper.stop(:split_update_worker, @config)
38
+ @queue = nil
32
39
  end
33
40
 
34
41
  private
@@ -46,7 +53,7 @@ module SplitIoClient
46
53
 
47
54
  def perform_thread
48
55
  @config.threads[:split_update_worker] = Thread.new do
49
- @config.logger.debug('Starting splits worker ...')
56
+ @config.logger.debug('Starting splits worker ...') if @config.debug_enabled
50
57
  perform
51
58
  end
52
59
  end
@@ -1,3 +1,3 @@
1
1
  module SplitIoClient
2
- VERSION = '7.1.0.pre.rc4'
2
+ VERSION = '7.1.0.pre.rc5'
3
3
  end
@@ -98,7 +98,6 @@ require 'splitclient-rb/sse/event_source/back_off'
98
98
  require 'splitclient-rb/sse/event_source/client'
99
99
  require 'splitclient-rb/sse/event_source/event_types'
100
100
  require 'splitclient-rb/sse/event_source/stream_data'
101
- require 'splitclient-rb/sse/workers/control_worker'
102
101
  require 'splitclient-rb/sse/workers/segments_worker'
103
102
  require 'splitclient-rb/sse/workers/splits_worker'
104
103
  require 'splitclient-rb/sse/notification_manager_keeper'
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.1.0.pre.rc4
4
+ version: 7.1.0.pre.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Split Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-19 00:00:00.000000000 Z
11
+ date: 2020-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allocation_stats
@@ -424,7 +424,6 @@ files:
424
424
  - lib/splitclient-rb/sse/notification_manager_keeper.rb
425
425
  - lib/splitclient-rb/sse/notification_processor.rb
426
426
  - lib/splitclient-rb/sse/sse_handler.rb
427
- - lib/splitclient-rb/sse/workers/control_worker.rb
428
427
  - lib/splitclient-rb/sse/workers/segments_worker.rb
429
428
  - lib/splitclient-rb/sse/workers/splits_worker.rb
430
429
  - lib/splitclient-rb/utilitites.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SplitIoClient
4
- module SSE
5
- module Workers
6
- class ControlWorker
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
- def start
12
- perform_thread
13
- perform_passenger_forked if defined?(PhusionPassenger)
14
- end
15
-
16
- def stop
17
- SplitIoClient::Helpers::ThreadHelper.stop(:control_worker, @config)
18
- end
19
-
20
- private
21
-
22
- def perform
23
- # TODO: IMPLEMENT THIS METHOD.
24
- end
25
-
26
- def perform_thread
27
- @config.threads[:control_worker] = Thread.new do
28
- @config.logger.debug('Starting control worker ...')
29
- perform
30
- end
31
- end
32
-
33
- def perform_passenger_forked
34
- PhusionPassenger.on_event(:starting_worker_process) { |forked| perform_thread if forked }
35
- end
36
- end
37
- end
38
- end
39
- end