sidekiq-bus 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/sidekiq_bus/adapter.rb +1 -1
- data/lib/sidekiq_bus/middleware/retry.rb +10 -10
- data/lib/sidekiq_bus/tasks.rb +4 -4
- data/lib/sidekiq_bus/version.rb +3 -1
- data/spec/adapter/integration_spec.rb +45 -45
- data/spec/adapter/support.rb +2 -0
- data/spec/adapter_spec.rb +2 -1
- data/spec/application_spec.rb +97 -97
- data/spec/config_spec.rb +26 -29
- data/spec/dispatch_spec.rb +39 -40
- data/spec/driver_spec.rb +60 -58
- data/spec/heartbeat_spec.rb +26 -24
- data/spec/integration_spec.rb +41 -40
- data/spec/matcher_spec.rb +104 -102
- data/spec/publish_spec.rb +46 -46
- data/spec/publisher_spec.rb +3 -1
- data/spec/rider_spec.rb +16 -14
- data/spec/spec_helper.rb +9 -8
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +29 -29
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +13 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c633c91c5b55a5e08ec80f73ee6a174df07d59c
|
4
|
+
data.tar.gz: '00095d6bcdc1407137cab9051990b91f359df304'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4dcb3d6a379ceda40fe1da42c6cdb00662b85f37bbfcf9010ed7303883d8e44a9f43f9ab9c587793503ce4ade15a09f1c23cbdd6ec07ae5f4d85af0ce8ced04
|
7
|
+
data.tar.gz: 2631baff2bc6724686516f34cc04955fef78884228566f961b2f51dd069130bf67c65a562200299e833b241d8ed18c6e7a17636768bfd6310d318de1c8997c0f
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
### [0.8.2] - 2019-08-06
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Schedule now uses cron format to schedule heartbeat. The "every: 1min" format was causing multiple heartbeats to fire in the same minute if there were multiple sidekiq processes with the dynamic setting turned off (which is default).
|
13
|
+
|
9
14
|
### [0.8.1] - 2019-08-05
|
10
15
|
|
11
16
|
### Fixed
|
data/lib/sidekiq_bus/adapter.rb
CHANGED
@@ -57,7 +57,7 @@ module QueueBus
|
|
57
57
|
def set_schedule(queue_name)
|
58
58
|
::Sidekiq.set_schedule(
|
59
59
|
'sidekiqbus_heartbeat',
|
60
|
-
|
60
|
+
cron: '0 * * * * *', # Runs every minute
|
61
61
|
class: ::QueueBus::Worker.name,
|
62
62
|
args: [
|
63
63
|
::QueueBus::Util.encode('bus_class_proxy' => ::QueueBus::Heartbeat.name)
|
@@ -1,18 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SidekiqBus
|
2
4
|
module Middleware
|
3
5
|
module Client
|
4
|
-
|
5
6
|
# ensure sidekiq will retry jobs even when they are enqueued via other adapters
|
6
7
|
class Retry
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def call(_worker_class, job, _queue, _redis_pool)
|
9
|
+
if job['class'] == 'QueueBus::Worker'
|
10
|
+
job['retry'] = true unless job.key?('retry')
|
11
|
+
job['backtrace'] = true unless job.key?('backtrace')
|
12
|
+
end
|
13
|
+
yield
|
14
|
+
end
|
14
15
|
end
|
15
|
-
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
data/lib/sidekiq_bus/tasks.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# require 'sidekiq_bus/tasks'
|
2
4
|
# will give you these tasks
|
3
5
|
|
4
|
-
require
|
6
|
+
require 'queue_bus/tasks'
|
5
7
|
|
6
8
|
namespace :queuebus do
|
7
|
-
|
8
9
|
# Preload app files if this is Rails
|
9
10
|
task :preload do
|
10
|
-
require
|
11
|
+
require 'sidekiq'
|
11
12
|
end
|
12
|
-
|
13
13
|
end
|
data/lib/sidekiq_bus/version.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
|
-
if Sidekiq::VERSION < '4'
|
3
|
-
require 'celluloid'
|
4
|
-
end
|
4
|
+
require 'celluloid' if Sidekiq::VERSION < '4'
|
5
5
|
require 'sidekiq/scheduled'
|
6
6
|
|
7
|
-
describe
|
8
|
-
describe
|
7
|
+
describe 'Sidekiq Integration' do
|
8
|
+
describe 'Happy Path' do
|
9
9
|
before(:each) do
|
10
10
|
Sidekiq::Testing.fake!
|
11
|
-
QueueBus.dispatch(
|
12
|
-
subscribe
|
11
|
+
QueueBus.dispatch('r1') do
|
12
|
+
subscribe 'event_name' do |attributes|
|
13
13
|
QueueBus::Runner1.run(attributes)
|
14
14
|
end
|
15
15
|
end
|
@@ -17,11 +17,11 @@ describe "Sidekiq Integration" do
|
|
17
17
|
QueueBus::TaskManager.new(false).subscribe!
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'should publish and receive' do
|
21
21
|
Sidekiq::Testing.fake!
|
22
22
|
expect(QueueBus::Runner1.value).to eq(0)
|
23
23
|
|
24
|
-
QueueBus.publish(
|
24
|
+
QueueBus.publish('event_name', 'ok' => true)
|
25
25
|
expect(QueueBus::Runner1.value).to eq(0)
|
26
26
|
|
27
27
|
QueueBus::Worker.perform_one
|
@@ -33,58 +33,59 @@ describe "Sidekiq Integration" do
|
|
33
33
|
expect(QueueBus::Runner1.value).to eq(1)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'should publish and receive' do
|
37
37
|
Sidekiq::Testing.inline!
|
38
38
|
expect(QueueBus::Runner1.value).to eq(0)
|
39
39
|
|
40
|
-
QueueBus.publish(
|
40
|
+
QueueBus.publish('event_name', 'ok' => true)
|
41
41
|
expect(QueueBus::Runner1.value).to eq(1)
|
42
42
|
end
|
43
|
-
|
44
43
|
end
|
45
44
|
|
46
|
-
describe
|
45
|
+
describe 'Delayed Publishing' do
|
47
46
|
before(:each) do
|
48
47
|
Timecop.freeze(now)
|
49
|
-
allow(QueueBus).to receive(:generate_uuid).and_return(
|
48
|
+
allow(QueueBus).to receive(:generate_uuid).and_return('idfhlkj')
|
50
49
|
end
|
51
50
|
after(:each) do
|
52
51
|
Timecop.return
|
53
52
|
end
|
54
|
-
let(:delayed_attrs)
|
55
|
-
|
56
|
-
|
53
|
+
let(:delayed_attrs) do
|
54
|
+
{ 'bus_delayed_until' => future.to_i,
|
55
|
+
'bus_id' => "#{now.to_i}-idfhlkj",
|
56
|
+
'bus_app_hostname' => Socket.gethostname }
|
57
|
+
end
|
57
58
|
|
58
|
-
let(:bus_attrs) { delayed_attrs.merge(
|
59
|
-
let(:now) { Time.parse(
|
59
|
+
let(:bus_attrs) { delayed_attrs.merge('bus_published_at' => worktime.to_i) }
|
60
|
+
let(:now) { Time.parse('01/01/2013 5:00') }
|
60
61
|
let(:future) { Time.at(now.to_i + 60) }
|
61
|
-
let(:worktime) {Time.at(future.to_i + 1)}
|
62
|
+
let(:worktime) { Time.at(future.to_i + 1) }
|
62
63
|
|
63
|
-
it
|
64
|
-
hash = {:one => 1,
|
65
|
-
event_name =
|
64
|
+
it 'should add it to Redis' do
|
65
|
+
hash = { :one => 1, 'two' => 'here', 'id' => 12 }
|
66
|
+
event_name = 'event_name'
|
66
67
|
QueueBus.publish_at(future, event_name, hash)
|
67
68
|
|
68
|
-
val = QueueBus.redis { |redis| redis.zrange(
|
69
|
+
val = QueueBus.redis { |redis| redis.zrange('schedule', 0, 1) }.first
|
69
70
|
|
70
71
|
hash = JSON.parse(val)
|
71
72
|
|
72
|
-
expect(hash[
|
73
|
-
expect(hash[
|
74
|
-
expect(JSON.parse(hash[
|
75
|
-
expect(hash[
|
73
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
74
|
+
expect(hash['args'].size).to eq(1)
|
75
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Publisher', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(delayed_attrs))
|
76
|
+
expect(hash['queue']).to eq('bus_incoming')
|
76
77
|
end
|
77
78
|
|
78
|
-
it
|
79
|
-
hash = {:one => 1,
|
80
|
-
event_name =
|
79
|
+
it 'should move it to the real queue when processing' do
|
80
|
+
hash = { :one => 1, 'two' => 'here', 'id' => 12 }
|
81
|
+
event_name = 'event_name'
|
81
82
|
|
82
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
83
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
83
84
|
expect(val).to eq(nil)
|
84
85
|
|
85
86
|
QueueBus.publish_at(future, event_name, hash)
|
86
87
|
|
87
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
88
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
88
89
|
expect(val).to eq(nil) # nothing really added
|
89
90
|
|
90
91
|
if Sidekiq::VERSION < '4'
|
@@ -93,7 +94,7 @@ describe "Sidekiq Integration" do
|
|
93
94
|
Sidekiq::Scheduled::Poller.new.enqueue
|
94
95
|
end
|
95
96
|
|
96
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
97
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
97
98
|
expect(val).to eq(nil) # nothing added yet
|
98
99
|
|
99
100
|
# process scheduler in future
|
@@ -104,21 +105,20 @@ describe "Sidekiq Integration" do
|
|
104
105
|
Sidekiq::Scheduled::Poller.new.enqueue
|
105
106
|
end
|
106
107
|
|
107
|
-
val = QueueBus.redis { |redis| redis.lpop(
|
108
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
108
109
|
hash = JSON.parse(val)
|
109
|
-
expect(hash[
|
110
|
-
expect(hash[
|
111
|
-
expect(JSON.parse(hash[
|
110
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
111
|
+
expect(hash['args'].size).to eq(1)
|
112
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Publisher', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(delayed_attrs))
|
112
113
|
|
113
|
-
|
114
|
+
QueueBus::Publisher.perform(JSON.parse(hash['args'].first))
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
117
|
+
hash = JSON.parse(val)
|
118
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
119
|
+
expect(hash['args'].size).to eq(1)
|
120
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Driver', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(bus_attrs))
|
120
121
|
end
|
121
122
|
end
|
122
|
-
|
123
123
|
end
|
124
124
|
end
|
data/spec/adapter/support.rb
CHANGED
data/spec/adapter_spec.rb
CHANGED
@@ -40,7 +40,8 @@ describe 'adapter is set' do
|
|
40
40
|
|
41
41
|
shared_examples 'a scheduled heartbeat' do
|
42
42
|
it 'has the schedule for every minute' do
|
43
|
-
expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['every']).to
|
43
|
+
expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['every']).to be_nil
|
44
|
+
expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['cron']).to eq '0 * * * * *'
|
44
45
|
end
|
45
46
|
|
46
47
|
it 'has scheduled the queue bus worker' do
|
data/spec/application_spec.rb
CHANGED
@@ -1,151 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Application do
|
5
|
-
describe
|
6
|
-
it
|
7
|
+
describe '.all' do
|
8
|
+
it 'should return empty array when none' do
|
7
9
|
expect(Application.all).to eq([])
|
8
10
|
end
|
9
|
-
it
|
10
|
-
Application.new(
|
11
|
-
Application.new(
|
12
|
-
Application.new(
|
11
|
+
it 'should return registered applications when there are some' do
|
12
|
+
Application.new('One').subscribe(test_list(test_sub('fdksjh')))
|
13
|
+
Application.new('Two').subscribe(test_list(test_sub('fdklhf')))
|
14
|
+
Application.new('Three').subscribe(test_list(test_sub('fkld')))
|
13
15
|
|
14
|
-
expect(Application.all.collect(&:app_key)).to match_array([
|
16
|
+
expect(Application.all.collect(&:app_key)).to match_array(%w[one two three])
|
15
17
|
|
16
|
-
Application.new(
|
17
|
-
expect(Application.all.collect(&:app_key)).to match_array([
|
18
|
+
Application.new('two').unsubscribe
|
19
|
+
expect(Application.all.collect(&:app_key)).to match_array(%w[one three])
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
describe
|
22
|
-
it
|
23
|
-
expect(Application.new(
|
23
|
+
describe '.new' do
|
24
|
+
it 'should have a key' do
|
25
|
+
expect(Application.new('something').app_key).to eq('something')
|
24
26
|
|
25
|
-
expect(Application.new(
|
26
|
-
expect(Application.new(
|
27
|
-
expect(Application.new(
|
28
|
-
expect(Application.new(
|
27
|
+
expect(Application.new('some thing').app_key).to eq('some_thing')
|
28
|
+
expect(Application.new('some-thing').app_key).to eq('some_thing')
|
29
|
+
expect(Application.new('some_thing').app_key).to eq('some_thing')
|
30
|
+
expect(Application.new('Some Thing').app_key).to eq('some_thing')
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
32
|
-
expect
|
33
|
-
Application.new(
|
34
|
-
|
33
|
+
it 'should raise an error if not valid' do
|
34
|
+
expect do
|
35
|
+
Application.new('')
|
36
|
+
end.to raise_error('Invalid application name')
|
35
37
|
|
36
|
-
expect
|
38
|
+
expect do
|
37
39
|
Application.new(nil)
|
38
|
-
|
40
|
+
end.to raise_error('Invalid application name')
|
39
41
|
|
40
|
-
expect
|
41
|
-
Application.new(
|
42
|
-
|
42
|
+
expect do
|
43
|
+
Application.new('/')
|
44
|
+
end.to raise_error('Invalid application name')
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
describe
|
47
|
-
it
|
48
|
-
|
49
|
-
QueueBus.redis { |redis| redis.hset(
|
50
|
-
|
51
|
-
app = Application.new("myapp")
|
48
|
+
describe '#read_redis_hash' do
|
49
|
+
it 'should handle old and new values' do
|
50
|
+
QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'new_one', QueueBus::Util.encode('queue_name' => 'x', 'bus_event_type' => 'event_name')) }
|
51
|
+
QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'old_one', 'oldqueue_name') }
|
52
|
+
app = Application.new('myapp')
|
52
53
|
val = app.send(:read_redis_hash)
|
53
|
-
expect(val).to eq(
|
54
|
+
expect(val).to eq('new_one' => { 'queue_name' => 'x', 'bus_event_type' => 'event_name' }, 'old_one' => 'oldqueue_name')
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
describe
|
58
|
-
let(:sub1) { test_sub(
|
59
|
-
let(:sub2) { test_sub(
|
60
|
-
let(:sub3) { test_sub(
|
61
|
-
it
|
62
|
-
expect(QueueBus.redis { |redis| redis.get(
|
63
|
-
Application.new(
|
64
|
-
|
65
|
-
expect(QueueBus.redis { |redis| redis.hgetall(
|
66
|
-
|
67
|
-
expect(QueueBus.redis { |redis| redis.hkeys(
|
68
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
58
|
+
describe '#subscribe' do
|
59
|
+
let(:sub1) { test_sub('event_one', 'default') }
|
60
|
+
let(:sub2) { test_sub('event_two', 'default') }
|
61
|
+
let(:sub3) { test_sub('event_three', 'other') }
|
62
|
+
it 'should add array to redis' do
|
63
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
64
|
+
Application.new('myapp').subscribe(test_list(sub1, sub2))
|
65
|
+
|
66
|
+
expect(QueueBus.redis { |redis| redis.hgetall('bus_app:myapp') }).to eq('event_two' => '{"queue_name":"default","key":"event_two","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_two"}}',
|
67
|
+
'event_one' => '{"queue_name":"default","key":"event_one","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_one"}}')
|
68
|
+
expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(%w[event_one event_two])
|
69
|
+
expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
|
69
70
|
end
|
70
|
-
it
|
71
|
-
expect(QueueBus.redis { |redis| redis.get(
|
72
|
-
Application.new(
|
71
|
+
it 'should add string to redis' do
|
72
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
73
|
+
Application.new('myapp').subscribe(test_list(sub1))
|
73
74
|
|
74
|
-
expect(QueueBus.redis { |redis| redis.hgetall(
|
75
|
-
expect(QueueBus.redis { |redis| redis.hkeys(
|
76
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
75
|
+
expect(QueueBus.redis { |redis| redis.hgetall('bus_app:myapp') }).to eq('event_one' => '{"queue_name":"default","key":"event_one","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_one"}}')
|
76
|
+
expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(['event_one'])
|
77
|
+
expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
|
77
78
|
end
|
78
|
-
it
|
79
|
-
expect(QueueBus.redis { |redis| redis.get(
|
80
|
-
Application.new(
|
81
|
-
expect(QueueBus.redis { |redis| redis.hgetall(
|
82
|
-
|
83
|
-
expect(QueueBus.redis { |redis| redis.hkeys(
|
84
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
79
|
+
it 'should multiple queues to redis' do
|
80
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
81
|
+
Application.new('myapp').subscribe(test_list(sub1, sub2, sub3))
|
82
|
+
expect(QueueBus.redis { |redis| redis.hgetall('bus_app:myapp') }).to eq('event_two' => '{"queue_name":"default","key":"event_two","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_two"}}', 'event_one' => '{"queue_name":"default","key":"event_one","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_one"}}',
|
83
|
+
'event_three' => '{"queue_name":"other","key":"event_three","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_three"}}')
|
84
|
+
expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(%w[event_three event_two event_one])
|
85
|
+
expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
|
85
86
|
end
|
86
87
|
|
87
|
-
it
|
88
|
-
|
89
|
-
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
88
|
+
it 'should do nothing if nil or empty' do
|
89
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
90
90
|
|
91
|
-
Application.new(
|
92
|
-
expect(QueueBus.redis { |redis| redis.get(
|
91
|
+
Application.new('myapp').subscribe(nil)
|
92
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
93
93
|
|
94
|
-
Application.new(
|
95
|
-
expect(QueueBus.redis { |redis| redis.get(
|
94
|
+
Application.new('myapp').subscribe([])
|
95
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
99
|
-
app = Application.new(
|
98
|
+
it 'should call unsubscribe' do
|
99
|
+
app = Application.new('myapp')
|
100
100
|
expect(app).to receive(:unsubscribe)
|
101
101
|
app.subscribe([])
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe
|
106
|
-
it
|
107
|
-
QueueBus.redis { |redis| redis.sadd(
|
108
|
-
QueueBus.redis { |redis| redis.sadd(
|
109
|
-
QueueBus.redis { |redis| redis.hset(
|
105
|
+
describe '#unsubscribe' do
|
106
|
+
it 'should remove items' do
|
107
|
+
QueueBus.redis { |redis| redis.sadd('bus_apps', 'myapp') }
|
108
|
+
QueueBus.redis { |redis| redis.sadd('bus_apps', 'other') }
|
109
|
+
QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'event_one', 'myapp_default') }
|
110
110
|
|
111
|
-
Application.new(
|
111
|
+
Application.new('myapp').unsubscribe
|
112
112
|
|
113
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
114
|
-
expect(QueueBus.redis { |redis| redis.get(
|
113
|
+
expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to eq(['other'])
|
114
|
+
expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
describe
|
119
|
-
it
|
120
|
-
expect(Application.new(
|
118
|
+
describe '#subscription_matches' do
|
119
|
+
it 'should return if it is there' do
|
120
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'three').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
121
121
|
|
122
|
-
subs = test_list(test_sub(
|
123
|
-
Application.new(
|
124
|
-
expect(Application.new(
|
122
|
+
subs = test_list(test_sub('one_x'), test_sub('one_y'), test_sub('one'), test_sub('two'))
|
123
|
+
Application.new('myapp').subscribe(subs)
|
124
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'three').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
125
125
|
|
126
|
-
expect(Application.new(
|
127
|
-
expect(Application.new(
|
126
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'two').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'two', 'default', '::QueueBus::Rider']])
|
127
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'one').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'one', 'default', '::QueueBus::Rider']])
|
128
128
|
end
|
129
129
|
|
130
|
-
it
|
131
|
-
subs = test_list(test_sub(
|
132
|
-
Application.new(
|
133
|
-
expect(Application.new(
|
130
|
+
it 'should handle * wildcards' do
|
131
|
+
subs = test_list(test_sub('one.+'), test_sub('one'), test_sub('one_.*'), test_sub('two'))
|
132
|
+
Application.new('myapp').subscribe(subs)
|
133
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'three').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
134
134
|
|
135
|
-
expect(Application.new(
|
136
|
-
expect(Application.new(
|
137
|
-
expect(Application.new(
|
135
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'onex').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'one.+', 'default', '::QueueBus::Rider']])
|
136
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'one').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'one', 'default', '::QueueBus::Rider']])
|
137
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'one_x').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'one.+', 'default', '::QueueBus::Rider'], ['myapp', 'one_.*', 'default', '::QueueBus::Rider']])
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
141
|
-
subs = test_list(test_sub(/one.+/), test_sub(
|
142
|
-
Application.new(
|
143
|
-
expect(Application.new(
|
140
|
+
it 'should handle actual regular expressions' do
|
141
|
+
subs = test_list(test_sub(/one.+/), test_sub('one'), test_sub(/one_.*/), test_sub('two'))
|
142
|
+
Application.new('myapp').subscribe(subs)
|
143
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'three').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
144
144
|
|
145
|
-
expect(Application.new(
|
146
|
-
expect(Application.new(
|
147
|
-
expect(Application.new(
|
148
|
-
expect(Application.new(
|
145
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'onex').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', '(?-mix:one.+)', 'default', '::QueueBus::Rider']])
|
146
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'donex').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', '(?-mix:one.+)', 'default', '::QueueBus::Rider']])
|
147
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'one').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', 'one', 'default', '::QueueBus::Rider']])
|
148
|
+
expect(Application.new('myapp').subscription_matches('bus_event_type' => 'one_x').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['myapp', '(?-mix:one.+)', 'default', '::QueueBus::Rider'], ['myapp', '(?-mix:one_.*)', 'default', '::QueueBus::Rider']])
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|