pubsubstub 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfd7d496f0e2ce3d0a48c9bc7a88a96b53d14150
4
- data.tar.gz: c4849cbfb57dc5f9415edd74beb2737592d35921
3
+ metadata.gz: 6549edd3271aea9f63868a73df5e2d7abbac4cc3
4
+ data.tar.gz: 771ff6a8653ff3f956ba5396b1bbcef79f6f6eb4
5
5
  SHA512:
6
- metadata.gz: b6a1b5013dbaef4a34fc7486f9f8095818d599a1083d0361c9e57a9b51698d92048eff0d524d924b6a9826e401583ba572a04c477ba2919c57812d34d02c1212
7
- data.tar.gz: 818686cfa16835e0a430c830b4af65fc61820217bc08da80cd9b3128f69f2fa4d8e6828424dcc7b9aa2f2305f34b833744e83cf8e75e193a11587579ee1cecb4
6
+ metadata.gz: fc27ef10f261293dc52adf96789fb5c7de4ac1065cc4a2b8257f3c36d9afe63c9a4c734c90c923d43bc2960404e733bdbe6c525a91197e15b6a166361bde8a4f
7
+ data.tar.gz: 3ccd4fb1ef9886ba092d1d33d16c9d8e013a165f31eeb6f229354fea5fa6bc89bb3f115fd465f15f2cfac8a3817aa82589aa1f50aa53bfb9bb5f074e2da9d26c
data/lib/pubsubstub.rb CHANGED
@@ -21,7 +21,8 @@ module Pubsubstub
21
21
 
22
22
  class << self
23
23
  attr_accessor :heartbeat_frequency, :redis_url, :channels_scrollback_size,
24
- :channels_scrollback_ttl, :logger, :reconnect_timeout, :error_handler
24
+ :channels_scrollback_ttl, :logger, :reconnect_timeout, :error_handler,
25
+ :use_persistent_connections
25
26
 
26
27
  def publish(channel_name, *args)
27
28
  Channel.new(channel_name).publish(Event.new(*args))
@@ -69,6 +70,7 @@ module Pubsubstub
69
70
  self.channels_scrollback_size = 1000
70
71
  self.channels_scrollback_ttl = 24 * 60 * 60
71
72
  self.reconnect_timeout = 10_000
73
+ self.use_persistent_connections = true
72
74
 
73
75
  # Deprecated. Use Pubsubstub.publish instead
74
76
  module RedisPubSub
@@ -19,10 +19,10 @@ module Pubsubstub
19
19
  request = Rack::Request.new(env)
20
20
  channels = (request.params['channels'] || [:default]).map(&Channel.method(:new))
21
21
 
22
- stream = if event_machine?
23
- send_scrollback(channels, last_event_id)
24
- else
22
+ stream = if use_persistent_connections?
25
23
  subscribe_connection(channels, last_event_id)
24
+ else
25
+ send_scrollback(channels, last_event_id)
26
26
  end
27
27
  [200, HEADERS, stream]
28
28
  end
@@ -40,6 +40,10 @@ module Pubsubstub
40
40
  end
41
41
  end
42
42
 
43
+ def use_persistent_connections?
44
+ Pubsubstub.use_persistent_connections && !event_machine?
45
+ end
46
+
43
47
  def event_machine?
44
48
  defined?(EventMachine) && EventMachine.reactor_running?
45
49
  end
@@ -1,3 +1,3 @@
1
1
  module Pubsubstub
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/channel_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pubsubstub::Channel do
3
+ RSpec.describe Pubsubstub::Channel do
4
4
  subject { described_class.new('foobar') }
5
5
 
6
6
  it "has a name" do
data/spec/event_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pubsubstub::Event do
3
+ RSpec.describe Pubsubstub::Event do
4
4
  subject {
5
5
  Pubsubstub::Event.new("refresh #1500\nnew #1400", id: 12345678, name: "toto", retry_after: 1_000)
6
6
  }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pubsubstub::StreamAction do
3
+ RSpec.describe Pubsubstub::StreamAction do
4
4
  let(:app) { Pubsubstub::PublishAction.new }
5
5
  let(:channel) { Pubsubstub::Channel.new('foo') }
6
6
 
@@ -1,5 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
+ RSpec.shared_examples "short lived connections" do
4
+ it "immediately returns the scrollback" do
5
+ Pubsubstub.publish('foo', 'bar', id: 1)
6
+ Pubsubstub.publish('foo', 'baz', id: 2)
7
+
8
+ get '/?channels[]=foo', {}, 'HTTP_LAST_EVENT_ID' => 1
9
+ expect(last_response.body).to eq("id: 2\ndata: baz\n\n")
10
+ end
11
+
12
+ it "returns and heartbeat if scrollback is empty" do
13
+ Timecop.freeze('2015-01-01T00:00:00+00:00') do
14
+ get '/'
15
+ message = "id: 1420070400000\nevent: heartbeat\nretry: #{Pubsubstub.reconnect_timeout}\ndata: ping\n\n"
16
+ expect(last_response.body).to eq(message)
17
+ end
18
+ end
19
+ end
20
+
3
21
  describe Pubsubstub::StreamAction do
4
22
  let(:app) { Pubsubstub::StreamAction.new }
5
23
 
@@ -8,21 +26,18 @@ describe Pubsubstub::StreamAction do
8
26
  allow(EventMachine).to receive(:reactor_running?).and_return(true)
9
27
  end
10
28
 
11
- it "immediately returns the scrollback" do
12
- Pubsubstub.publish('foo', 'bar', id: 1)
13
- Pubsubstub.publish('foo', 'baz', id: 2)
29
+ it_behaves_like "short lived connections"
30
+ end
14
31
 
15
- get '/?channels[]=foo', {}, 'HTTP_LAST_EVENT_ID' => 1
16
- expect(last_response.body).to eq("id: 2\ndata: baz\n\n")
32
+ context "with persistent connections disabled" do
33
+ around :example do |example|
34
+ previous = Pubsubstub.use_persistent_connections
35
+ Pubsubstub.use_persistent_connections = false
36
+ example.run
37
+ Pubsubstub.use_persistent_connections = previous
17
38
  end
18
39
 
19
- it "returns and heartbeat if scrollback is empty" do
20
- Timecop.freeze('2015-01-01T00:00:00+00:00') do
21
- get '/'
22
- message = "id: 1420070400000\nevent: heartbeat\nretry: #{Pubsubstub.reconnect_timeout}\ndata: ping\n\n"
23
- expect(last_response.body).to eq(message)
24
- end
25
- end
40
+ it_behaves_like "short lived connections"
26
41
  end
27
42
 
28
43
  it "immediately send a heartbeat event if there is no scrollback" do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pubsubstub::Subscriber do
3
+ RSpec.describe Pubsubstub::Subscriber do
4
4
  describe "#start" do
5
5
  let(:channel) { Pubsubstub::Channel.new('plop') }
6
6
  let(:events) { (1..10).map { |i| Pubsubstub::Event.new("refresh ##{i}", id: i) } }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pubsubstub::Subscription do
3
+ RSpec.describe Pubsubstub::Subscription do
4
4
  let(:event) { Pubsubstub::Event.new('hello') }
5
5
  let(:connection) { [] }
6
6
  let(:channels) { %w(foo bar).map(&Pubsubstub::Channel.method(:new)) }
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsubstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Malette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  description: Pubsubstub can be added to a rack Application or deployed standalone.
@@ -62,9 +62,9 @@ executables:
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
- - ".gitignore"
66
- - ".rspec"
67
- - ".travis.yml"
65
+ - .gitignore
66
+ - .rspec
67
+ - .travis.yml
68
68
  - Gemfile
69
69
  - LICENSE.txt
70
70
  - README.md
@@ -109,17 +109,17 @@ require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ">="
112
+ - - '>='
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ">="
117
+ - - '>='
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.5.1
122
+ rubygems_version: 2.0.14.1
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Pubsubstub is a rack middleware to add Pub/Sub