splitclient-rb 7.2.0.pre.rc1 → 7.2.0

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: 26c30b8e429b82a364a8738b157f9837aa7c0063e4e928eba564ddca250a4350
4
- data.tar.gz: 709736898887b3e24169bc0728380b04bf3f321754c24f51526db4f661d331a7
3
+ metadata.gz: d5a8bad0b7b72fba188bff72b10b5a0849bdadabdde484929b83071a51cfe715
4
+ data.tar.gz: 27b74c33b6fbe6c87141bf163f1dbd8d37eaa586d8c60eb73319cbcb7e3cc85e
5
5
  SHA512:
6
- metadata.gz: 621a75e4a9839183d1d327a76cfb093c286345e68f87660345d1321c53050919aac7733af400ce19b575e266f38ec8ffa0109edc917712063271a3c51fbf1b32
7
- data.tar.gz: e46f618031d6f83be2f2be332a842b0424206da5cf711637190a1e8d561741cbe65380a67a07d8819a3eff7c93e1c7c7f79c98fcb40b546d158dd9af3f6f8bb6
6
+ metadata.gz: 0db37fb36974d3b177b3b4b08d35199bf828b8c4ebc508731e1255c44c08f9be2953174e6dbb3b1a2d514f880845b0abefd300061ad9b77e72745a867b930dc4
7
+ data.tar.gz: 0d66fc9a82f117ed7ccc4e391aa59827ed024d34d3082472dab54d6c3cacd57357c01af6eb6becb69f8a0dabc12cc51258e0e7a852fbfc9c82d414eb1ad1d40b
@@ -101,7 +101,6 @@ require 'splitclient-rb/redis_metrics_fixer'
101
101
  # SSE
102
102
  require 'splitclient-rb/sse/event_source/back_off'
103
103
  require 'splitclient-rb/sse/event_source/client'
104
- require 'splitclient-rb/sse/event_source/event_parser'
105
104
  require 'splitclient-rb/sse/event_source/event_types'
106
105
  require 'splitclient-rb/sse/event_source/stream_data'
107
106
  require 'splitclient-rb/sse/workers/segments_worker'
@@ -142,7 +142,7 @@ module SplitIoClient
142
142
 
143
143
  # General
144
144
  def exists?(key)
145
- @redis.exists?(key)
145
+ @redis.exists(key)
146
146
  end
147
147
 
148
148
  def delete(key)
@@ -15,15 +15,14 @@ module SplitIoClient
15
15
  response = @auth_api_client.authenticate(@api_key)
16
16
 
17
17
  @config.logger.debug("Auth service response push_enabled: #{response[:push_enabled]}") if @config.debug_enabled
18
-
19
- if response[:push_enabled] && @sse_handler.start(response[:token], response[:channels])
18
+ if response[:push_enabled]
19
+ @sse_handler.start(response[:token], response[:channels])
20
20
  schedule_next_token_refresh(response[:exp])
21
21
  @back_off.reset
22
- return
22
+ else
23
+ stop_sse
23
24
  end
24
25
 
25
- stop_sse
26
-
27
26
  schedule_next_token_refresh(@back_off.interval) if response[:retry]
28
27
  rescue StandardError => e
29
28
  @config.logger.error("start_sse: #{e.inspect}")
@@ -32,7 +31,6 @@ module SplitIoClient
32
31
  def stop_sse
33
32
  @sse_handler.process_disconnect if @sse_handler.sse_client.nil?
34
33
  @sse_handler.stop
35
- SplitIoClient::Helpers::ThreadHelper.stop(:schedule_next_token_refresh, @config)
36
34
  end
37
35
 
38
36
  private
@@ -43,7 +41,7 @@ module SplitIoClient
43
41
  @config.logger.debug("schedule_next_token_refresh refresh in #{time} seconds.") if @config.debug_enabled
44
42
  sleep(time)
45
43
  @config.logger.debug('schedule_next_token_refresh starting ...') if @config.debug_enabled
46
- @sse_handler.stop
44
+ stop_sse
47
45
  start_sse
48
46
  rescue StandardError => e
49
47
  @config.logger.debug("schedule_next_token_refresh error: #{e.inspect}") if @config.debug_enabled
@@ -3,13 +3,19 @@
3
3
  module SplitIoClient
4
4
  module Engine
5
5
  class SyncManager
6
+ include SplitIoClient::Cache::Fetchers
7
+
6
8
  def initialize(
7
9
  repositories,
8
10
  api_key,
9
11
  config,
10
- synchronizer
12
+ params
11
13
  )
12
- @synchronizer = synchronizer
14
+ split_fetcher = SplitFetcher.new(repositories[:splits], api_key, params[:metrics], config, params[:sdk_blocker])
15
+ segment_fetcher = SegmentFetcher.new(repositories[:segments], api_key, params[:metrics], config, params[:sdk_blocker])
16
+ sync_params = { split_fetcher: split_fetcher, segment_fetcher: segment_fetcher, imp_counter: params[:impression_counter] }
17
+
18
+ @synchronizer = Synchronizer.new(repositories, api_key, config, params[:sdk_blocker], sync_params)
13
19
  notification_manager_keeper = SplitIoClient::SSE::NotificationManagerKeeper.new(config) do |manager|
14
20
  manager.on_occupancy { |publisher_available| process_occupancy(publisher_available) }
15
21
  manager.on_push_shutdown { process_push_shutdown }
@@ -22,11 +28,10 @@ module SplitIoClient
22
28
  notification_manager_keeper
23
29
  ) do |handler|
24
30
  handler.on_connected { process_connected }
25
- handler.on_disconnect { |reconnect| process_disconnect(reconnect) }
31
+ handler.on_disconnect { process_disconnect }
26
32
  end
27
33
 
28
34
  @push_manager = PushManager.new(config, @sse_handler, api_key)
29
- @sse_connected = Concurrent::AtomicBoolean.new(false)
30
35
  @config = config
31
36
  end
32
37
 
@@ -85,12 +90,6 @@ module SplitIoClient
85
90
  end
86
91
 
87
92
  def process_connected
88
- if @sse_connected.value
89
- @config.logger.debug('Streaming already connected.')
90
- return
91
- end
92
-
93
- @sse_connected.make_true
94
93
  @synchronizer.stop_periodic_fetch
95
94
  @synchronizer.sync_all
96
95
  @sse_handler.start_workers
@@ -98,42 +97,23 @@ module SplitIoClient
98
97
  @config.logger.error("process_connected error: #{e.inspect}")
99
98
  end
100
99
 
101
- def process_disconnect(reconnect)
102
- unless @sse_connected.value
103
- @config.logger.debug('Streaming already disconnected.')
104
- return
105
- end
106
-
107
- @sse_connected.make_false
100
+ def process_disconnect
108
101
  @sse_handler.stop_workers
109
102
  @synchronizer.start_periodic_fetch
110
-
111
- if reconnect
112
- @synchronizer.sync_all
113
- @push_manager.start_sse
114
- end
115
103
  rescue StandardError => e
116
104
  @config.logger.error("process_disconnect error: #{e.inspect}")
117
105
  end
118
106
 
119
107
  def process_occupancy(push_enable)
120
- if push_enable
121
- @synchronizer.stop_periodic_fetch
122
- @synchronizer.sync_all
123
- @sse_handler.start_workers
124
- return
125
- end
126
-
127
- @sse_handler.stop_workers
128
- @synchronizer.start_periodic_fetch
108
+ process_disconnect unless push_enable
109
+ process_connected if push_enable
129
110
  rescue StandardError => e
130
111
  @config.logger.error("process_occupancy error: #{e.inspect}")
131
112
  end
132
113
 
133
114
  def process_push_shutdown
134
115
  @push_manager.stop_sse
135
- @sse_handler.stop_workers
136
- @synchronizer.start_periodic_fetch
116
+ process_disconnect
137
117
  rescue StandardError => e
138
118
  @config.logger.error("process_push_shutdown error: #{e.inspect}")
139
119
  end
@@ -28,11 +28,9 @@ module SplitIoClient
28
28
  end
29
29
 
30
30
  def sync_all
31
- @config.threads[:sync_all_thread] = Thread.new do
32
- @config.logger.debug('Synchronizing Splits and Segments ...') if @config.debug_enabled
33
- fetch_splits
34
- fetch_segments
35
- end
31
+ @config.logger.debug('Synchronizing Splits and Segments ...') if @config.debug_enabled
32
+ fetch_splits
33
+ fetch_segments
36
34
  end
37
35
 
38
36
  def start_periodic_data_recording
@@ -7,7 +7,6 @@ module SplitIoClient
7
7
  include SplitIoClient::Cache::Repositories
8
8
  include SplitIoClient::Cache::Stores
9
9
  include SplitIoClient::Cache::Senders
10
- include SplitIoClient::Cache::Fetchers
11
10
 
12
11
  attr_reader :adapter, :client, :manager, :config
13
12
 
@@ -54,12 +53,8 @@ module SplitIoClient
54
53
  if @config.localhost_mode
55
54
  start_localhost_components
56
55
  else
57
- split_fetcher = SplitFetcher.new(@splits_repository, @api_key, @metrics, config, @sdk_blocker)
58
- segment_fetcher = SegmentFetcher.new(@segments_repository, @api_key, @metrics, config, @sdk_blocker)
59
- params = { split_fetcher: split_fetcher, segment_fetcher: segment_fetcher, imp_counter: @impression_counter }
60
-
61
- synchronizer = SplitIoClient::Engine::Synchronizer.new(repositories, @api_key, @config, @sdk_blocker, params)
62
- SplitIoClient::Engine::SyncManager.new(repositories, @api_key, @config, synchronizer).start
56
+ params = { sdk_blocker: @sdk_blocker, metrics: @metrics, impression_counter: @impression_counter }
57
+ SplitIoClient::Engine::SyncManager.new(repositories, @api_key, @config, params).start
63
58
  end
64
59
  end
65
60
 
@@ -130,13 +125,14 @@ module SplitIoClient
130
125
  end
131
126
 
132
127
  def repositories
133
- {
134
- splits: @splits_repository,
135
- segments: @segments_repository,
136
- impressions: @impressions_repository,
137
- events: @events_repository,
138
- metrics: @metrics_repository
139
- }
128
+ repos = {}
129
+ repos[:splits] = @splits_repository
130
+ repos[:segments] = @segments_repository
131
+ repos[:impressions] = @impressions_repository
132
+ repos[:events] = @events_repository
133
+ repos[:metrics] = @metrics_repository
134
+
135
+ repos
140
136
  end
141
137
 
142
138
  def start_localhost_components
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: false
2
2
 
3
+ require 'concurrent/atomics'
3
4
  require 'socketry'
4
5
  require 'uri'
5
6
 
@@ -8,16 +9,15 @@ module SplitIoClient
8
9
  module EventSource
9
10
  class Client
10
11
  DEFAULT_READ_TIMEOUT = 70
11
- CONNECT_TIMEOUT = 30_000
12
12
  KEEP_ALIVE_RESPONSE = "c\r\n:keepalive\n\n\r\n".freeze
13
- ERROR_EVENT_TYPE = 'error'.freeze
14
13
 
15
14
  def initialize(config, read_timeout: DEFAULT_READ_TIMEOUT)
16
15
  @config = config
17
16
  @read_timeout = read_timeout
18
17
  @connected = Concurrent::AtomicBoolean.new(false)
19
18
  @socket = nil
20
- @event_parser = SSE::EventSource::EventParser.new(config)
19
+ @back_off = BackOff.new(@config.streaming_reconnect_back_off_base)
20
+
21
21
  @on = { event: ->(_) {}, connected: ->(_) {}, disconnect: ->(_) {} }
22
22
 
23
23
  yield self if block_given?
@@ -35,8 +35,8 @@ module SplitIoClient
35
35
  @on[:disconnect] = action
36
36
  end
37
37
 
38
- def close(reconnect = false)
39
- dispatch_disconnect(reconnect)
38
+ def close
39
+ dispatch_disconnect
40
40
  @connected.make_false
41
41
  SplitIoClient::Helpers::ThreadHelper.stop(:connect_stream, @config)
42
42
  @socket&.close
@@ -46,16 +46,10 @@ module SplitIoClient
46
46
 
47
47
  def start(url)
48
48
  @uri = URI(url)
49
- latch = Concurrent::CountDownLatch.new(1)
50
-
51
- connect_thread(latch)
52
49
 
53
- return false unless latch.wait(CONNECT_TIMEOUT)
54
-
55
- connected?
50
+ connect_thread
56
51
  rescue StandardError => e
57
52
  @config.logger.error("SSEClient start Error: #{e.inspect}")
58
- connected?
59
53
  end
60
54
 
61
55
  def connected?
@@ -64,15 +58,18 @@ module SplitIoClient
64
58
 
65
59
  private
66
60
 
67
- def connect_thread(latch)
61
+ def connect_thread
68
62
  @config.threads[:connect_stream] = Thread.new do
69
63
  @config.logger.info('Starting connect_stream thread ...') if @config.debug_enabled
70
- connect_stream(latch)
64
+ connect_stream
71
65
  end
72
66
  end
73
67
 
74
- def connect_stream(latch)
75
- socket_write(latch)
68
+ def connect_stream
69
+ interval = @back_off.interval
70
+ sleep(interval) if interval.positive?
71
+
72
+ socket_write
76
73
 
77
74
  while @connected.value
78
75
  begin
@@ -80,24 +77,24 @@ module SplitIoClient
80
77
 
81
78
  raise 'eof exception' if partial_data == :eof
82
79
  rescue StandardError => e
83
- @config.logger.error('Error reading partial data: ' + e.inspect) if @config.debug_enabled
84
- close(true) # close conexion & reconnect
85
- return
80
+ @config.logger.error(e.inspect) if @config.debug_enabled
81
+ @connected.make_false
82
+ @socket&.close
83
+ @socket = nil
84
+ connect_stream
86
85
  end
87
86
 
88
87
  process_data(partial_data)
89
88
  end
90
89
  end
91
90
 
92
- def socket_write(latch)
91
+ def socket_write
93
92
  @socket = socket_connect
94
93
  @socket.write(build_request(@uri))
95
94
  dispatch_connected
96
95
  rescue StandardError => e
97
96
  @config.logger.error("Error during connecting to #{@uri.host}. Error: #{e.inspect}")
98
97
  close
99
- ensure
100
- latch.count_down
101
98
  end
102
99
 
103
100
  def socket_connect
@@ -107,11 +104,11 @@ module SplitIoClient
107
104
  end
108
105
 
109
106
  def process_data(partial_data)
110
- return if partial_data.nil? || partial_data == KEEP_ALIVE_RESPONSE
111
-
112
- @config.logger.debug("Event partial data: #{partial_data}") if @config.debug_enabled
113
- events = @event_parser.parse(partial_data)
114
- events.each { |event| process_event(event) }
107
+ unless partial_data.nil? || partial_data == KEEP_ALIVE_RESPONSE
108
+ @config.logger.debug("Event partial data: #{partial_data}") if @config.debug_enabled
109
+ buffer = read_partial_data(partial_data)
110
+ parse_event(buffer)
111
+ end
115
112
  rescue StandardError => e
116
113
  @config.logger.error("process_data error: #{e.inspect}")
117
114
  end
@@ -125,38 +122,64 @@ module SplitIoClient
125
122
  req
126
123
  end
127
124
 
128
- def process_event(event)
129
- case event.event_type
130
- when ERROR_EVENT_TYPE
131
- dispatch_error(event)
132
- else
133
- dispatch_event(event)
134
- end
125
+ def read_partial_data(data)
126
+ buffer = ''
127
+ buffer << data
128
+ buffer.chomp!
129
+ buffer.split("\n")
135
130
  end
136
131
 
137
- def dispatch_error(event)
138
- @config.logger.error("Event error: #{event.event_type}, #{event.data}")
139
- if event.data['code'] >= 40_140 && event.data['code'] <= 40_149
140
- close(true) # close conexion & reconnect
141
- elsif event.data['code'] >= 40_000 && event.data['code'] <= 49_999
142
- close # close conexion
132
+ def parse_event(buffer)
133
+ type = nil
134
+
135
+ buffer.each do |d|
136
+ splited_data = d.split(':')
137
+
138
+ case splited_data[0]
139
+ when 'event'
140
+ type = splited_data[1].strip
141
+ when 'data'
142
+ data = parse_event_data(d, type)
143
+ unless type.nil? || data[:data].nil?
144
+ event = StreamData.new(type, data[:client_id], data[:data], data[:channel])
145
+ dispatch_event(event)
146
+ end
147
+ end
143
148
  end
149
+ rescue StandardError => e
150
+ @config.logger.error("Error during parsing a event: #{e.inspect}")
151
+ end
152
+
153
+ def parse_event_data(data, type)
154
+ event_data = JSON.parse(data.sub('data: ', ''))
155
+ client_id = event_data['clientId']&.strip
156
+ channel = event_data['channel']&.strip
157
+ parsed_data = JSON.parse(event_data['data']) unless type == 'error'
158
+ parsed_data = event_data if type == 'error'
159
+
160
+ { client_id: client_id, channel: channel, data: parsed_data }
144
161
  end
145
162
 
146
163
  def dispatch_event(event)
164
+ raise SSEClientException.new(event), 'Error event' if event.event_type == 'error'
165
+
147
166
  @config.logger.debug("Dispatching event: #{event.event_type}, #{event.channel}") if @config.debug_enabled
148
167
  @on[:event].call(event)
168
+ rescue SSEClientException => e
169
+ @config.logger.error("Event error: #{e.event.event_type}, #{e.event.data}")
170
+ close
149
171
  end
150
172
 
151
173
  def dispatch_connected
152
174
  @connected.make_true
175
+ @back_off.reset
153
176
  @config.logger.debug('Dispatching connected') if @config.debug_enabled
154
177
  @on[:connected].call
155
178
  end
156
179
 
157
- def dispatch_disconnect(reconnect)
180
+ def dispatch_disconnect
158
181
  @config.logger.debug('Dispatching disconnect') if @config.debug_enabled
159
- @on[:disconnect].call(reconnect)
182
+ @on[:disconnect].call
160
183
  end
161
184
  end
162
185
  end
@@ -14,7 +14,7 @@ module SplitIoClient
14
14
  @sse_client = SSE::EventSource::Client.new(@config) do |client|
15
15
  client.on_event { |event| handle_incoming_message(event) }
16
16
  client.on_connected { process_connected }
17
- client.on_disconnect { |reconnect| process_disconnect(reconnect) }
17
+ client.on_disconnect { process_disconnect }
18
18
  end
19
19
 
20
20
  @on = { connected: ->(_) {}, disconnect: ->(_) {} }
@@ -56,8 +56,8 @@ module SplitIoClient
56
56
  @on[:disconnect] = action
57
57
  end
58
58
 
59
- def process_disconnect(reconnect)
60
- @on[:disconnect].call(reconnect)
59
+ def process_disconnect
60
+ @on[:disconnect].call
61
61
  end
62
62
 
63
63
  private
@@ -8,39 +8,27 @@ module SplitIoClient
8
8
  @synchronizer = synchronizer
9
9
  @config = config
10
10
  @segments_repository = segments_repository
11
+ @queue = nil
12
+ end
13
+
14
+ def start
15
+ return if SplitIoClient::Helpers::ThreadHelper.alive?(:segment_update_worker, @config)
16
+
11
17
  @queue = Queue.new
12
- @running = Concurrent::AtomicBoolean.new(false)
18
+ perform_thread
13
19
  end
14
20
 
15
21
  def add_to_queue(change_number, segment_name)
16
- unless @running.value
17
- @config.logger.debug('segments worker not running.')
18
- return
19
- end
22
+ return if @queue.nil?
20
23
 
21
24
  item = { change_number: change_number, segment_name: segment_name }
22
25
  @config.logger.debug("SegmentsWorker add to queue #{item}")
23
26
  @queue.push(item)
24
27
  end
25
28
 
26
- def start
27
- if @running.value
28
- @config.logger.debug('segments worker already running.')
29
- return
30
- end
31
-
32
- @running.make_true
33
- perform_thread
34
- end
35
-
36
29
  def stop
37
- unless @running.value
38
- @config.logger.debug('segments worker not running.')
39
- return
40
- end
41
-
42
- @running.make_false
43
30
  SplitIoClient::Helpers::ThreadHelper.stop(:segment_update_worker, @config)
31
+ @queue = nil
44
32
  end
45
33
 
46
34
  private
@@ -8,53 +8,35 @@ module SplitIoClient
8
8
  @synchronizer = synchronizer
9
9
  @config = config
10
10
  @splits_repository = splits_repository
11
- @queue = Queue.new
12
- @running = Concurrent::AtomicBoolean.new(false)
13
11
  end
14
12
 
15
13
  def start
16
- if @running.value
17
- @config.logger.debug('splits worker already running.')
18
- return
19
- end
14
+ return if SplitIoClient::Helpers::ThreadHelper.alive?(:split_update_worker, @config)
20
15
 
21
- @running.make_true
16
+ @queue = Queue.new
22
17
  perform_thread
23
18
  end
24
19
 
25
- def stop
26
- unless @running.value
27
- @config.logger.debug('splits worker not running.')
28
- return
29
- end
30
-
31
- @running.make_false
32
- SplitIoClient::Helpers::ThreadHelper.stop(:split_update_worker, @config)
33
- end
34
-
35
20
  def add_to_queue(change_number)
36
- unless @running.value
37
- @config.logger.debug('splits worker not running.')
38
- return
39
- end
21
+ return if @queue.nil?
40
22
 
41
23
  @config.logger.debug("SplitsWorker add to queue #{change_number}")
42
24
  @queue.push(change_number)
43
25
  end
44
26
 
45
27
  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
- return if @splits_repository.get_change_number.to_i > change_number
28
+ return if @queue.nil?
52
29
 
53
30
  @config.logger.debug("SplitsWorker kill #{split_name}, #{change_number}")
54
31
  @splits_repository.kill(change_number, split_name, default_treatment)
55
32
  add_to_queue(change_number)
56
33
  end
57
34
 
35
+ def stop
36
+ SplitIoClient::Helpers::ThreadHelper.stop(:split_update_worker, @config)
37
+ @queue = nil
38
+ end
39
+
58
40
  private
59
41
 
60
42
  def perform
@@ -1,3 +1,3 @@
1
1
  module SplitIoClient
2
- VERSION = '7.2.0.pre.rc1'
2
+ VERSION = '7.2.0'
3
3
  end
@@ -55,7 +55,7 @@ Gem::Specification.new do |spec|
55
55
  spec.add_runtime_dependency 'jwt', '>= 2.2.1'
56
56
  spec.add_runtime_dependency 'lru_redux'
57
57
  spec.add_runtime_dependency 'net-http-persistent', '>= 2.9'
58
- spec.add_runtime_dependency 'redis', '>= 4.2.2'
58
+ spec.add_runtime_dependency 'redis', '>= 3.2'
59
59
  spec.add_runtime_dependency 'socketry', '~> 0.5.1'
60
60
  spec.add_runtime_dependency 'thread_safe', '>= 0.3'
61
61
  end
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.2.0.pre.rc1
4
+ version: 7.2.0
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-10-19 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allocation_stats
@@ -268,14 +268,14 @@ dependencies:
268
268
  requirements:
269
269
  - - ">="
270
270
  - !ruby/object:Gem::Version
271
- version: 4.2.2
271
+ version: '3.2'
272
272
  type: :runtime
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
276
  - - ">="
277
277
  - !ruby/object:Gem::Version
278
- version: 4.2.2
278
+ version: '3.2'
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: socketry
281
281
  requirement: !ruby/object:Gem::Requirement
@@ -425,7 +425,6 @@ files:
425
425
  - lib/splitclient-rb/split_logger.rb
426
426
  - lib/splitclient-rb/sse/event_source/back_off.rb
427
427
  - lib/splitclient-rb/sse/event_source/client.rb
428
- - lib/splitclient-rb/sse/event_source/event_parser.rb
429
428
  - lib/splitclient-rb/sse/event_source/event_types.rb
430
429
  - lib/splitclient-rb/sse/event_source/stream_data.rb
431
430
  - lib/splitclient-rb/sse/notification_manager_keeper.rb
@@ -455,9 +454,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
455
454
  version: '0'
456
455
  required_rubygems_version: !ruby/object:Gem::Requirement
457
456
  requirements:
458
- - - ">"
457
+ - - ">="
459
458
  - !ruby/object:Gem::Version
460
- version: 1.3.1
459
+ version: '0'
461
460
  requirements: []
462
461
  rubygems_version: 3.0.6
463
462
  signing_key:
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- module SplitIoClient
4
- module SSE
5
- module EventSource
6
- class EventParser
7
- def initialize(config)
8
- @config = config
9
- end
10
-
11
- def parse(raw_event)
12
- type = nil
13
- events = []
14
- buffer = read_partial_data(raw_event)
15
-
16
- buffer.each do |d|
17
- splited_data = d.split(':')
18
-
19
- case splited_data[0]
20
- when 'event'
21
- type = splited_data[1].strip
22
- when 'data'
23
- data = parse_event_data(d, type)
24
- events << StreamData.new(type, data[:client_id], data[:data], data[:channel]) unless type.nil? || data[:data].nil?
25
- end
26
- end
27
-
28
- events
29
- rescue StandardError => e
30
- @config.logger.error("Error during parsing a event: #{e.inspect}")
31
- []
32
- end
33
-
34
- private
35
-
36
- def parse_event_data(data, type)
37
- event_data = JSON.parse(data.sub('data: ', ''))
38
- client_id = event_data['clientId']&.strip
39
- channel = event_data['channel']&.strip
40
- parsed_data = JSON.parse(event_data['data']) unless type == 'error'
41
- parsed_data = event_data if type == 'error'
42
-
43
- { client_id: client_id, channel: channel, data: parsed_data }
44
- end
45
-
46
- def read_partial_data(data)
47
- buffer = ''
48
- buffer << data
49
- buffer.chomp!
50
- buffer.split("\n")
51
- end
52
- end
53
- end
54
- end
55
- end