pubsubstub 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pubsubstub.rb +3 -1
- data/lib/pubsubstub/stream_action.rb +7 -3
- data/lib/pubsubstub/version.rb +1 -1
- data/spec/channel_spec.rb +1 -1
- data/spec/event_spec.rb +1 -1
- data/spec/publish_action_spec.rb +1 -1
- data/spec/stream_action_spec.rb +27 -12
- data/spec/subscriber_spec.rb +1 -1
- data/spec/subscription_spec.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6549edd3271aea9f63868a73df5e2d7abbac4cc3
|
4
|
+
data.tar.gz: 771ff6a8653ff3f956ba5396b1bbcef79f6f6eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/pubsubstub/version.rb
CHANGED
data/spec/channel_spec.rb
CHANGED
data/spec/event_spec.rb
CHANGED
data/spec/publish_action_spec.rb
CHANGED
data/spec/stream_action_spec.rb
CHANGED
@@ -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
|
-
|
12
|
-
|
13
|
-
Pubsubstub.publish('foo', 'baz', id: 2)
|
29
|
+
it_behaves_like "short lived connections"
|
30
|
+
end
|
14
31
|
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
data/spec/subscriber_spec.rb
CHANGED
data/spec/subscription_spec.rb
CHANGED
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.
|
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-
|
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
|
-
-
|
66
|
-
-
|
67
|
-
-
|
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.
|
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
|