pubsubstub 0.2.1 → 0.2.2
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 +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/Gemfile +3 -5
- data/lib/pubsubstub/channel.rb +5 -5
- data/lib/pubsubstub/stream_action.rb +3 -11
- data/lib/pubsubstub/version.rb +1 -1
- data/pubsubstub.gemspec +1 -1
- data/spec/spec_helper.rb +0 -11
- data/spec/stream_action_spec.rb +6 -10
- data/spec/support/http_helpers.rb +2 -2
- metadata +5 -9
- data/.travis.yml +0 -14
- data/gemfiles/Gemfile.rack-1.x +0 -12
- data/gemfiles/Gemfile.rack-1.x.lock +0 -57
- data/gemfiles/Gemfile.rack-2.x +0 -12
- data/gemfiles/Gemfile.rack-2.x.lock +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c8dd8515862da676e40ce08fc68bbacc2c3fc1a5d5774fe0120c45606a0f40e
|
4
|
+
data.tar.gz: b09ba3fcf02b39d4f119daecb8ea8e6099ae06d60466d88c04602a51f654be90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76cb8590bb052cfd85426def3697bbf17a870119c6720469a42a2bb3ae5a33e960ccfb4d983855d30525134870a3b71443b19a59279d62180b45b80562938867
|
7
|
+
data.tar.gz: 6f8ff354315f011a332f0a838c499adfcd8cb8c5ad8fa0905376abf9fa8541dc232a56400dfe591eae3f5f82a7ca4f44347b3cdfa1b9dee517d88f83bcc5d8e9
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Tests with Ruby ${{ matrix.ruby_version }}
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
ruby_version:
|
13
|
+
- '2.7'
|
14
|
+
- '3.0'
|
15
|
+
- '3.1'
|
16
|
+
|
17
|
+
services:
|
18
|
+
redis:
|
19
|
+
image: redis
|
20
|
+
ports:
|
21
|
+
- 6379:6379
|
22
|
+
options: --entrypoint redis-server
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v1
|
26
|
+
- name: Set up Ruby ${{ matrix.ruby_version }}
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby_version }}
|
30
|
+
bundler-cache: true
|
31
|
+
- name: Run tests
|
32
|
+
env:
|
33
|
+
RAILS_ENV: test
|
34
|
+
run: |
|
35
|
+
bundle exec rake
|
data/Gemfile
CHANGED
@@ -3,11 +3,9 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in pubsubstub.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem "
|
8
|
-
gem "
|
9
|
-
gem "puma", "~> 3.4"
|
10
|
-
gem "thin", "~> 1.6"
|
6
|
+
gem "rspec"
|
7
|
+
gem "puma"
|
8
|
+
gem "thin"
|
11
9
|
gem "rack-test"
|
12
10
|
gem "timecop"
|
13
11
|
gem "rake"
|
data/lib/pubsubstub/channel.rb
CHANGED
@@ -13,11 +13,11 @@ module Pubsubstub
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def publish(event)
|
16
|
-
redis.pipelined do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
redis.pipelined do |pipeline|
|
17
|
+
pipeline.zadd(scrollback_key, event.id, event.to_json)
|
18
|
+
pipeline.zremrangebyrank(scrollback_key, 0, -Pubsubstub.channels_scrollback_size)
|
19
|
+
pipeline.expire(scrollback_key, Pubsubstub.channels_scrollback_ttl)
|
20
|
+
pipeline.publish(pubsub_key, event.to_json)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -41,11 +41,7 @@ module Pubsubstub
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def use_persistent_connections?
|
44
|
-
Pubsubstub.use_persistent_connections
|
45
|
-
end
|
46
|
-
|
47
|
-
def event_machine?
|
48
|
-
defined?(EventMachine) && EventMachine.reactor_running?
|
44
|
+
Pubsubstub.use_persistent_connections
|
49
45
|
end
|
50
46
|
|
51
47
|
def subscribe_connection(channels, last_event_id)
|
@@ -74,12 +70,8 @@ module Pubsubstub
|
|
74
70
|
@mutex.synchronize do
|
75
71
|
return if defined? @helper_threads_initialized
|
76
72
|
@helper_threads_initialized = true
|
77
|
-
|
78
|
-
|
79
|
-
else
|
80
|
-
start_subscriber
|
81
|
-
start_heartbeat
|
82
|
-
end
|
73
|
+
start_subscriber
|
74
|
+
start_heartbeat
|
83
75
|
end
|
84
76
|
end
|
85
77
|
|
data/lib/pubsubstub/version.rb
CHANGED
data/pubsubstub.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["gmalette@gmail.com"]
|
11
11
|
spec.summary = %q{Pubsubstub is a rack middleware to add Pub/Sub}
|
12
12
|
spec.description = %q{Pubsubstub can be added to a rack Application or deployed standalone. It uses Redis to do the Pub/Sub}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/byroot/pubsubstub"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'rack/test'
|
3
|
-
require 'pry'
|
4
|
-
require 'pry-byebug'
|
5
3
|
require 'timecop'
|
6
4
|
require 'thread'
|
7
5
|
|
@@ -16,15 +14,6 @@ require_relative '../lib/pubsubstub'
|
|
16
14
|
Pubsubstub.logger = Logger.new(nil)
|
17
15
|
Pubsubstub.logger.level = Logger::DEBUG
|
18
16
|
|
19
|
-
# Fake EM
|
20
|
-
module EventMachine
|
21
|
-
extend self
|
22
|
-
|
23
|
-
def reactor_running?
|
24
|
-
false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
17
|
RSpec.configure do |config|
|
29
18
|
config.include Rack::Test::Methods
|
30
19
|
config.include HTTPHelpers
|
data/spec/stream_action_spec.rb
CHANGED
@@ -21,14 +21,6 @@ end
|
|
21
21
|
describe Pubsubstub::StreamAction do
|
22
22
|
let(:app) { Pubsubstub::StreamAction.new }
|
23
23
|
|
24
|
-
context "with EventMachine" do
|
25
|
-
before do
|
26
|
-
allow(EventMachine).to receive(:reactor_running?).and_return(true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it_behaves_like "short lived connections"
|
30
|
-
end
|
31
|
-
|
32
24
|
context "with persistent connections disabled" do
|
33
25
|
around :example do |example|
|
34
26
|
previous = Pubsubstub.use_persistent_connections
|
@@ -44,7 +36,7 @@ describe Pubsubstub::StreamAction do
|
|
44
36
|
with_background_server do
|
45
37
|
expect(9292).to listen.in_under(5)
|
46
38
|
|
47
|
-
chunks = async_get('http://localhost:9292/?channels[]=foo', 'Last-Event-Id' => '0')
|
39
|
+
chunks, thread = async_get('http://localhost:9292/?channels[]=foo', { 'Last-Event-Id' => '0' })
|
48
40
|
expect(chunks.pop).to include("event: heartbeat\n")
|
49
41
|
|
50
42
|
Pubsubstub.publish('foo', 'bar', id: 1)
|
@@ -52,6 +44,8 @@ describe Pubsubstub::StreamAction do
|
|
52
44
|
|
53
45
|
Pubsubstub.publish('foo', 'baz', id: 2)
|
54
46
|
expect(chunks.pop).to include("id: 2\n")
|
47
|
+
ensure
|
48
|
+
thread.kill
|
55
49
|
end
|
56
50
|
end
|
57
51
|
|
@@ -61,11 +55,13 @@ describe Pubsubstub::StreamAction do
|
|
61
55
|
with_background_server do
|
62
56
|
expect(9292).to listen.in_under(5)
|
63
57
|
|
64
|
-
chunks = async_get('http://localhost:9292/?channels[]=foo', 'Last-Event-Id' => '0')
|
58
|
+
chunks, thread = async_get('http://localhost:9292/?channels[]=foo', { 'Last-Event-Id' => '0' })
|
65
59
|
expect(chunks.pop).to include("id: 1\n")
|
66
60
|
|
67
61
|
Pubsubstub.publish('foo', 'baz', id: 2)
|
68
62
|
expect(chunks.pop).to include("id: 2\n")
|
63
|
+
ensure
|
64
|
+
thread.kill
|
69
65
|
end
|
70
66
|
end
|
71
67
|
end
|
@@ -4,7 +4,7 @@ module HTTPHelpers
|
|
4
4
|
def async_get(uri, headers = {}, retries: 10, &block)
|
5
5
|
uri = URI(uri.to_s)
|
6
6
|
queue = Queue.new
|
7
|
-
Thread.start do
|
7
|
+
thread = Thread.start do
|
8
8
|
begin
|
9
9
|
Net::HTTP.start(uri.host, uri.port, open_timeout: 10) do |http|
|
10
10
|
request = Net::HTTP::Get.new uri.request_uri
|
@@ -33,7 +33,7 @@ module HTTPHelpers
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
queue
|
36
|
+
return queue, thread
|
37
37
|
end
|
38
38
|
|
39
39
|
ROOT_PATH = File.join(__dir__, '../..')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubsubstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Malette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -62,9 +62,9 @@ executables:
|
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
+
- ".github/workflows/ci.yml"
|
65
66
|
- ".gitignore"
|
66
67
|
- ".rspec"
|
67
|
-
- ".travis.yml"
|
68
68
|
- Gemfile
|
69
69
|
- LICENSE.txt
|
70
70
|
- README.md
|
@@ -74,10 +74,6 @@ files:
|
|
74
74
|
- example/Gemfile
|
75
75
|
- example/config.ru
|
76
76
|
- example/puma_config.rb
|
77
|
-
- gemfiles/Gemfile.rack-1.x
|
78
|
-
- gemfiles/Gemfile.rack-1.x.lock
|
79
|
-
- gemfiles/Gemfile.rack-2.x
|
80
|
-
- gemfiles/Gemfile.rack-2.x.lock
|
81
77
|
- lib/pubsubstub.rb
|
82
78
|
- lib/pubsubstub/application.rb
|
83
79
|
- lib/pubsubstub/channel.rb
|
@@ -99,7 +95,7 @@ files:
|
|
99
95
|
- spec/subscription_spec.rb
|
100
96
|
- spec/support/http_helpers.rb
|
101
97
|
- spec/support/threading_matchers.rb
|
102
|
-
homepage: https://github.com/
|
98
|
+
homepage: https://github.com/byroot/pubsubstub
|
103
99
|
licenses:
|
104
100
|
- MIT
|
105
101
|
metadata: {}
|
@@ -118,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
114
|
- !ruby/object:Gem::Version
|
119
115
|
version: '0'
|
120
116
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.3.3
|
122
118
|
signing_key:
|
123
119
|
specification_version: 4
|
124
120
|
summary: Pubsubstub is a rack middleware to add Pub/Sub
|
data/.travis.yml
DELETED
data/gemfiles/Gemfile.rack-1.x
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
byebug (10.0.2)
|
5
|
-
coderay (1.1.2)
|
6
|
-
daemons (1.3.1)
|
7
|
-
diff-lcs (1.3)
|
8
|
-
eventmachine (1.2.7)
|
9
|
-
method_source (0.9.2)
|
10
|
-
pry (0.12.2)
|
11
|
-
coderay (~> 1.1.0)
|
12
|
-
method_source (~> 0.9.0)
|
13
|
-
pry-byebug (3.6.0)
|
14
|
-
byebug (~> 10.0)
|
15
|
-
pry (~> 0.10)
|
16
|
-
puma (3.12.1)
|
17
|
-
rack (1.6.11)
|
18
|
-
rack-test (1.1.0)
|
19
|
-
rack (>= 1.0, < 3)
|
20
|
-
rake (12.3.3)
|
21
|
-
redis (4.1.2)
|
22
|
-
rspec (3.8.0)
|
23
|
-
rspec-core (~> 3.8.0)
|
24
|
-
rspec-expectations (~> 3.8.0)
|
25
|
-
rspec-mocks (~> 3.8.0)
|
26
|
-
rspec-core (3.8.2)
|
27
|
-
rspec-support (~> 3.8.0)
|
28
|
-
rspec-expectations (3.8.4)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.8.0)
|
31
|
-
rspec-mocks (3.8.1)
|
32
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.8.0)
|
34
|
-
rspec-support (3.8.2)
|
35
|
-
thin (1.7.2)
|
36
|
-
daemons (~> 1.0, >= 1.0.9)
|
37
|
-
eventmachine (~> 1.0, >= 1.0.4)
|
38
|
-
rack (>= 1, < 3)
|
39
|
-
timecop (0.9.1)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
byebug (~> 10.0)
|
46
|
-
pry-byebug
|
47
|
-
puma (~> 3.4)
|
48
|
-
rack (< 2)
|
49
|
-
rack-test
|
50
|
-
rake
|
51
|
-
redis (~> 4.0)
|
52
|
-
rspec (~> 3.8)
|
53
|
-
thin (~> 1.6)
|
54
|
-
timecop
|
55
|
-
|
56
|
-
BUNDLED WITH
|
57
|
-
1.17.3
|
data/gemfiles/Gemfile.rack-2.x
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
byebug (10.0.2)
|
5
|
-
coderay (1.1.2)
|
6
|
-
daemons (1.3.1)
|
7
|
-
diff-lcs (1.3)
|
8
|
-
eventmachine (1.2.7)
|
9
|
-
method_source (0.9.2)
|
10
|
-
pry (0.12.2)
|
11
|
-
coderay (~> 1.1.0)
|
12
|
-
method_source (~> 0.9.0)
|
13
|
-
pry-byebug (3.6.0)
|
14
|
-
byebug (~> 10.0)
|
15
|
-
pry (~> 0.10)
|
16
|
-
puma (3.12.1)
|
17
|
-
rack (2.0.7)
|
18
|
-
rack-test (1.1.0)
|
19
|
-
rack (>= 1.0, < 3)
|
20
|
-
rake (12.3.3)
|
21
|
-
redis (4.1.2)
|
22
|
-
rspec (3.8.0)
|
23
|
-
rspec-core (~> 3.8.0)
|
24
|
-
rspec-expectations (~> 3.8.0)
|
25
|
-
rspec-mocks (~> 3.8.0)
|
26
|
-
rspec-core (3.8.2)
|
27
|
-
rspec-support (~> 3.8.0)
|
28
|
-
rspec-expectations (3.8.4)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.8.0)
|
31
|
-
rspec-mocks (3.8.1)
|
32
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.8.0)
|
34
|
-
rspec-support (3.8.2)
|
35
|
-
thin (1.7.2)
|
36
|
-
daemons (~> 1.0, >= 1.0.9)
|
37
|
-
eventmachine (~> 1.0, >= 1.0.4)
|
38
|
-
rack (>= 1, < 3)
|
39
|
-
timecop (0.9.1)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
byebug (~> 10.0)
|
46
|
-
pry-byebug
|
47
|
-
puma (~> 3.4)
|
48
|
-
rack (~> 2.0)
|
49
|
-
rack-test
|
50
|
-
rake
|
51
|
-
redis (~> 4.0)
|
52
|
-
rspec (~> 3.8)
|
53
|
-
thin (~> 1.6)
|
54
|
-
timecop
|
55
|
-
|
56
|
-
BUNDLED WITH
|
57
|
-
1.17.3
|