ld-celluloid-eventsource 0.8.4 → 0.9.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
  SHA1:
3
- metadata.gz: e040451be340d3c8f933e665fb70c123736ac3fe
4
- data.tar.gz: 993d94fae833cb4ab05f6ca34475f427fa5fc462
3
+ metadata.gz: ae62916a2869d9f669a30e437e98f70c840e006e
4
+ data.tar.gz: 108da12046da7322ba51e2dd7fdaa6d28bdfeb43
5
5
  SHA512:
6
- metadata.gz: 97dd6a189803c922756b28dad8b8d8709a00be51650c03dfa92f2ff1aa58be2a0cf526eb47572cea800fd78eb73cfffc8999673def9e4fae3d0300ecedf82c38
7
- data.tar.gz: 7962621a8ce379de6578b898ad6d0b9c622003c877d9f9398b1015be90d82c07b72fb15f976742c4e5ab909aa3fa1e57338b26347fc28be524eb169e11211943
6
+ metadata.gz: 3b06a93d8c97309a27f95026a085648f36a2cb97d33dda6e93c87cd355d7c7637b05e2d08a47ec15280fbaeca6ce88a4be699dca74e05ecbe863a416d64112e3
7
+ data.tar.gz: e958aea737b951f0b9ece703cf94050390143614f9ad16a838f06d379c21fe7a3f42e5c608c06b35544372b52091715a6dd6cfcc5db9c00da5c4bcd41f893ea8
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Celluloid::Eventsource
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/celluloid-eventsource.png)](http://badge.fury.io/rb/ld-celluloid-eventsource)
3
+ [![Gem Version](https://badge.fury.io/rb/celluloid-eventsource.png)](http://badge.fury.io/rb/celluloid-eventsource)
4
+ [![Code Climate](https://codeclimate.com/github/Tonkpils/celluloid-eventsource.png)](https://codeclimate.com/github/Tonkpils/celluloid-eventsource)
5
+ [![Build Status](https://travis-ci.org/Tonkpils/celluloid-eventsource.svg?branch=master)](https://travis-ci.org/Tonkpils/celluloid-eventsource)
4
6
 
5
7
  An EventSource client based off Celluloid::IO.
6
8
 
@@ -10,7 +12,7 @@ Specification based on [EventSource](http://www.w3.org/TR/2012/CR-eventsource-20
10
12
 
11
13
  Add this line to your application's Gemfile:
12
14
 
13
- gem 'ld-celluloid-eventsource'
15
+ gem 'celluloid-eventsource'
14
16
 
15
17
  And then execute:
16
18
 
@@ -6,7 +6,7 @@ require 'celluloid/eventsource/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ld-celluloid-eventsource"
8
8
  spec.version = Celluloid::EventSource::VERSION
9
- spec.authors = ["LaunchDarky"]
9
+ spec.authors = ["LaunchDarkly"]
10
10
  spec.email = ["dev@launchdarkly.com"]
11
11
  spec.description = %q{Celluloid::IO based library to consume Server-Sent Events. This library was forked from https://github.com/Tonkpils/celluloid-eventsource}
12
12
  spec.summary = %q{ld-celluloid-eventsource is a gem to consume SSE streaming API.}
@@ -19,12 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'celluloid-io', '~> 0.17.3'
22
- spec.add_dependency 'celluloid', '~> 0.18.0.pre' # because https://github.com/celluloid/celluloid/issues/696
23
- spec.add_dependency 'nio4r', '~> 1.1'
22
+ spec.add_dependency 'celluloid', '~> 0.18.0.pre'
24
23
  spec.add_dependency 'http_parser.rb', '~> 0.6.0'
25
- spec.add_dependency 'concurrent-ruby', '~> 1.0'
26
- spec.add_dependency 'retries', '~> 0.0.5'
27
24
 
25
+ spec.add_development_dependency 'atomic', '~> 1.1'
28
26
  spec.add_development_dependency "rspec", '~> 3.0'
29
27
  spec.add_development_dependency "bundler", "~> 1.7"
30
28
  spec.add_development_dependency "rake", '~> 10.1'
@@ -1,10 +1,7 @@
1
1
  require 'celluloid/current'
2
- require 'celluloid/eventsource/version'
2
+ require "celluloid/eventsource/version"
3
3
  require 'celluloid/io'
4
4
  require 'celluloid/eventsource/response_parser'
5
- require 'concurrent'
6
- require 'logger'
7
- require 'retries'
8
5
  require 'uri'
9
6
 
10
7
  module Celluloid
@@ -12,17 +9,13 @@ module Celluloid
12
9
  include Celluloid::IO
13
10
  Celluloid.boot
14
11
 
15
- attr_reader :url, :with_credentials, :heartbeat_timeout, :logger
12
+ attr_reader :url, :with_credentials
16
13
  attr_reader :ready_state
17
14
 
18
15
  CONNECTING = 0
19
16
  OPEN = 1
20
17
  CLOSED = 2
21
18
 
22
- # 2^31 since our retries library doesn't allow for unlimited retries.
23
- # At an average of 1 second per retry, we'll still be retrying in 68 years.
24
- MAX_RETRIES = 2147483648
25
-
26
19
  execute_block_on_receiver :initialize
27
20
 
28
21
  def initialize(uri, options = {})
@@ -30,9 +23,6 @@ module Celluloid
30
23
  options = options.dup
31
24
  @ready_state = CONNECTING
32
25
  @with_credentials = options.delete(:with_credentials) { false }
33
- @heartbeat_timeout = options.delete(:heartbeat_timeout) { 300 }
34
- @logger = options.delete(:logger) { default_logger }
35
- @logger.info("[EventSource] Starting client connecting to url: #{self.url} with heartbeat timeout: #{@heartbeat_timeout} seconds")
36
26
  @headers = default_request_headers.merge(options.fetch(:headers, {}))
37
27
 
38
28
  @event_type_buffer = ""
@@ -42,7 +32,7 @@ module Celluloid
42
32
  @last_event_id = String.new
43
33
 
44
34
  @reconnect_timeout = 1
45
- @on = { open: ->{}, message: ->(_) {}, error: ->(_) {}}
35
+ @on = { open: ->{}, message: ->(_) {}, error: ->(_) {} }
46
36
  @parser = ResponseParser.new
47
37
 
48
38
  @chunked = false
@@ -69,25 +59,14 @@ module Celluloid
69
59
  begin
70
60
  establish_connection
71
61
  chunked? ? process_chunked_stream : process_stream
72
- rescue Exception => e
73
- logger.debug("[EventSource] Reconnecting after exception: #{e}")
62
+ rescue
63
+ # Just reconnect
74
64
  end
75
- sleep @reconnect_timeout
65
+ sleep @reconnect_timeout
76
66
  end
77
67
  end
78
68
 
79
- def listen_for_heartbeats
80
- @logger.debug("[EventSource] Starting listening for heartbeats. Reconnecting after #{@heartbeat_timeout} seconds if no comments are received")
81
- @heartbeat_task.cancel if @heartbeat_task
82
- @heartbeat_task = Concurrent::ScheduledTask.new(@heartbeat_timeout){
83
- @logger.warn("[EventSource] Didn't get heartbeat after #{@heartbeat_timeout} seconds. Reconnecting.")
84
- @socket.close if @socket
85
- }.execute
86
- end
87
-
88
69
  def close
89
- @logger.info("[EventSource] Closing client")
90
- @heartbeat_task.cancel if @heartbeat_task
91
70
  @socket.close if @socket
92
71
  @ready_state = CLOSED
93
72
  end
@@ -117,38 +96,31 @@ module Celluloid
117
96
  end
118
97
 
119
98
  def establish_connection
120
- handler = Proc.new do |exception, attempt_number, total_delay|
121
- logger.warn("[EventSource] Could not connect with exception: #{exception.class} #{exception.message}; retry attempt #{attempt_number}; #{total_delay} seconds have passed.")
122
- end
99
+ @socket = Celluloid::IO::TCPSocket.new(@url.host, @url.port)
123
100
 
124
- with_retries(:max_tries => MAX_RETRIES,
125
- :base_sleep_seconds => 1.0,
126
- :max_sleep_seconds => 30.0,
127
- :handler => handler,
128
- :rescue => Exception) do
129
- if !closed?
130
- @logger.info("[EventSource] Connecting to url: #{@url}")
131
- @socket = Celluloid::IO::TCPSocket.new(@url.host, @url.port)
132
-
133
- if ssl?
134
- @socket = Celluloid::IO::SSLSocket.new(@socket)
135
- @socket.connect
136
- end
137
-
138
- @socket.write(request_string)
101
+ if ssl?
102
+ @socket = Celluloid::IO::SSLSocket.new(@socket)
103
+ @socket.connect
104
+ end
139
105
 
140
- until @parser.headers?
141
- @parser << @socket.readline
142
- end
106
+ @socket.write(request_string)
143
107
 
144
- if @parser.status_code != 200
145
- @socket.close if @socket
146
- raise "[EventSource] Could not connect to stream. Got status code: #{@parser.status_code}"
147
- end
108
+ until @parser.headers?
109
+ @parser << @socket.readline
110
+ end
148
111
 
149
- handle_headers(@parser.headers)
112
+ if @parser.status_code != 200
113
+ until @socket.eof?
114
+ @parser << @socket.readline
150
115
  end
116
+ # If the server returns a non-200, we don't want to close-- we just want to
117
+ # report an error
118
+ # close
119
+ @on[:error].call({status_code: @parser.status_code, body: @parser.chunk})
120
+ return
151
121
  end
122
+
123
+ handle_headers(@parser.headers)
152
124
  end
153
125
 
154
126
  def default_request_headers
@@ -205,16 +177,14 @@ module Celluloid
205
177
 
206
178
  def parse_line(line)
207
179
  case line
208
- when /^: ?(.*)$/
209
- @logger.debug("[EventSource] Got comment: #{$1}")
210
- listen_for_heartbeats
211
- when /^(\w+): ?(.*)$/
212
- process_field($1, $2)
213
- else
214
- if chunked? && !@data_buffer.empty?
215
- @data_buffer.rstrip!
216
- process_field("data", line.rstrip)
217
- end
180
+ when /^:.*$/
181
+ when /^(\w+): ?(.*)$/
182
+ process_field($1, $2)
183
+ else
184
+ if chunked? && !@data_buffer.empty?
185
+ @data_buffer.rstrip!
186
+ process_field("data", line.rstrip)
187
+ end
218
188
  end
219
189
  end
220
190
 
@@ -227,7 +197,6 @@ module Celluloid
227
197
  event = MessageEvent.new(:message, @data_buffer, @last_event_id)
228
198
  event.type = @event_type_buffer.to_sym unless @event_type_buffer.empty?
229
199
 
230
- @logger.debug("[EventSource] Dispatching event: #{event}")
231
200
  dispatch_event(event)
232
201
  ensure
233
202
  clear_buffers!
@@ -253,11 +222,9 @@ module Celluloid
253
222
  @chunked = !headers["Transfer-Encoding"].nil? && headers["Transfer-Encoding"].include?("chunked")
254
223
  @ready_state = OPEN
255
224
  @on[:open].call
256
- @logger.info("[EventSource] Connected ok!")
257
- listen_for_heartbeats
258
225
  else
259
- @socket.close if @socket
260
- raise "Got invalid Content-Type header: #{headers['Content-Type']}. Expected text/event-stream"
226
+ close
227
+ @on[:error].call({status_code: @parser.status_code, body: "Invalid Content-Type #{headers['Content-Type']}. Expected text/event-stream"})
261
228
  end
262
229
  end
263
230
 
@@ -267,16 +234,6 @@ module Celluloid
267
234
  ["GET #{url.request_uri} HTTP/1.1", headers].flatten.join("\r\n").concat("\r\n\r\n")
268
235
  end
269
236
 
270
- def default_logger
271
- if defined?(Rails) && Rails.respond_to?(:logger)
272
- Rails.logger
273
- else
274
- log = ::Logger.new($stdout)
275
- log.level = ::Logger::INFO
276
- log
277
- end
278
- end
279
-
280
237
  end
281
238
 
282
239
  end
@@ -1,5 +1,5 @@
1
1
  module Celluloid
2
2
  class EventSource
3
- VERSION = "0.8.4"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ld-celluloid-eventsource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - LaunchDarky
7
+ - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.18.0.pre
41
- - !ruby/object:Gem::Dependency
42
- name: nio4r
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: http_parser.rb
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,33 +53,19 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: 0.6.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: concurrent-ruby
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.0'
83
- - !ruby/object:Gem::Dependency
84
- name: retries
56
+ name: atomic
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - "~>"
88
60
  - !ruby/object:Gem::Version
89
- version: 0.0.5
90
- type: :runtime
61
+ version: '1.1'
62
+ type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
66
  - - "~>"
95
67
  - !ruby/object:Gem::Version
96
- version: 0.0.5
68
+ version: '1.1'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: rspec
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +133,6 @@ files:
161
133
  - ".gitignore"
162
134
  - ".rspec"
163
135
  - ".travis.yml"
164
- - Contributing.md
165
136
  - Gemfile
166
137
  - LICENSE
167
138
  - README.md
@@ -196,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
167
  version: '0'
197
168
  requirements: []
198
169
  rubyforge_project:
199
- rubygems_version: 2.5.1
170
+ rubygems_version: 2.6.10
200
171
  signing_key:
201
172
  specification_version: 4
202
173
  summary: ld-celluloid-eventsource is a gem to consume SSE streaming API.
data/Contributing.md DELETED
@@ -1,7 +0,0 @@
1
- # Celluloid::Eventsource
2
-
3
- To release:
4
- 1. Bump version in version.rb
5
- 1. Commit changes and tag with version: ie 0.8.4
6
- 1. `VERSION=0.8.4 && git tag $VERSION && git push origin $VERSION && gem build ld-celluloid-eventsource.gemspec && gem push ld-celluloid-eventsource-$VERSION.gem`
7
- 1. Release on Github