queue-bus 0.6.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +4 -2
- data/README.mdown +16 -0
- data/Rakefile +2 -0
- data/lib/queue-bus.rb +15 -13
- data/lib/queue_bus/adapters/base.rb +4 -2
- data/lib/queue_bus/adapters/data.rb +12 -11
- data/lib/queue_bus/application.rb +13 -15
- data/lib/queue_bus/config.rb +64 -66
- data/lib/queue_bus/dispatch.rb +14 -12
- data/lib/queue_bus/dispatchers.rb +12 -5
- data/lib/queue_bus/driver.rb +15 -10
- data/lib/queue_bus/heartbeat.rb +32 -30
- data/lib/queue_bus/local.rb +9 -9
- data/lib/queue_bus/matcher.rb +36 -27
- data/lib/queue_bus/publisher.rb +7 -5
- data/lib/queue_bus/publishing.rb +31 -24
- data/lib/queue_bus/rider.rb +26 -22
- data/lib/queue_bus/subscriber.rb +20 -14
- data/lib/queue_bus/subscription.rb +25 -15
- data/lib/queue_bus/subscription_list.rb +30 -12
- data/lib/queue_bus/task_manager.rb +18 -16
- data/lib/queue_bus/tasks.rb +27 -11
- data/lib/queue_bus/util.rb +11 -8
- data/lib/queue_bus/version.rb +3 -1
- data/lib/queue_bus/worker.rb +3 -2
- data/queue-bus.gemspec +19 -17
- data/spec/adapter/publish_at_spec.rb +28 -25
- data/spec/adapter/support.rb +7 -1
- data/spec/adapter_spec.rb +4 -2
- data/spec/application_spec.rb +97 -97
- data/spec/config_spec.rb +116 -40
- data/spec/dispatch_spec.rb +48 -51
- 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 +12 -7
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +31 -31
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +17 -15
- metadata +21 -6
data/spec/config_spec.rb
CHANGED
@@ -1,83 +1,159 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module QueueBus
|
4
|
-
module Adapters
|
5
|
-
class TestOne
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
end
|
9
|
-
end
|
3
|
+
require 'spec_helper'
|
10
4
|
|
11
|
-
describe
|
12
|
-
it
|
5
|
+
describe 'QueueBus config' do
|
6
|
+
it 'sets the default app key' do
|
13
7
|
expect(QueueBus.default_app_key).to eq(nil)
|
14
8
|
|
15
|
-
QueueBus.default_app_key =
|
16
|
-
expect(QueueBus.default_app_key).to eq(
|
9
|
+
QueueBus.default_app_key = 'my_app'
|
10
|
+
expect(QueueBus.default_app_key).to eq('my_app')
|
17
11
|
|
18
|
-
QueueBus.default_app_key =
|
19
|
-
expect(QueueBus.default_app_key).to eq(
|
12
|
+
QueueBus.default_app_key = 'something here'
|
13
|
+
expect(QueueBus.default_app_key).to eq('something_here')
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
16
|
+
it 'sets the default queue' do
|
23
17
|
expect(QueueBus.default_queue).to eq(nil)
|
24
18
|
|
25
|
-
QueueBus.default_queue =
|
26
|
-
expect(QueueBus.default_queue).to eq(
|
19
|
+
QueueBus.default_queue = 'my_queue'
|
20
|
+
expect(QueueBus.default_queue).to eq('my_queue')
|
27
21
|
end
|
28
22
|
|
29
|
-
it
|
23
|
+
it 'sets the local mode' do
|
30
24
|
expect(QueueBus.local_mode).to eq(nil)
|
31
25
|
QueueBus.local_mode = :standalone
|
32
26
|
expect(QueueBus.local_mode).to eq(:standalone)
|
33
27
|
end
|
34
28
|
|
35
|
-
|
29
|
+
describe '#with_local_mode' do
|
30
|
+
it 'sets the local mode on the thread' do
|
31
|
+
QueueBus.with_local_mode(:suppress) do
|
32
|
+
expect(QueueBus.local_mode).to eq :suppress
|
33
|
+
Thread.new { expect(QueueBus.local_mode).to eq nil }.join
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'supports nesting' do
|
38
|
+
QueueBus.with_local_mode(:suppress) do
|
39
|
+
expect(QueueBus.local_mode).to eq :suppress
|
40
|
+
QueueBus.with_local_mode(:inline) do
|
41
|
+
expect(QueueBus.local_mode).to eq :inline
|
42
|
+
end
|
43
|
+
expect(QueueBus.local_mode).to eq :suppress
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'respects an override of nil' do
|
48
|
+
QueueBus.local_mode = :suppress
|
49
|
+
QueueBus.with_local_mode(nil) do
|
50
|
+
expect(QueueBus.local_mode).to eq nil
|
51
|
+
end
|
52
|
+
QueueBus.local_mode = :suppress
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'resets to the original local mode after the block' do
|
56
|
+
expect(QueueBus.local_mode).to eq nil
|
57
|
+
QueueBus.with_local_mode(:suppress) do
|
58
|
+
expect(QueueBus.local_mode).to eq :suppress
|
59
|
+
end
|
60
|
+
expect(QueueBus.local_mode).to eq nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets the hostname' do
|
36
65
|
expect(QueueBus.hostname).not_to eq(nil)
|
37
|
-
QueueBus.hostname =
|
38
|
-
expect(QueueBus.hostname).to eq(
|
66
|
+
QueueBus.hostname = 'whatever'
|
67
|
+
expect(QueueBus.hostname).to eq('whatever')
|
39
68
|
end
|
40
69
|
|
41
|
-
it
|
42
|
-
QueueBus.before_publish =
|
70
|
+
it 'sets before_publish callback' do
|
71
|
+
QueueBus.before_publish = ->(_attr) { 42 }
|
43
72
|
expect(QueueBus.before_publish_callback({})).to eq(42)
|
44
73
|
end
|
45
74
|
|
46
|
-
|
47
|
-
it "should use the default Redis connection" do
|
75
|
+
it 'uses the default Redis connection' do
|
48
76
|
expect(QueueBus.redis { |redis| redis }).not_to eq(nil)
|
49
77
|
end
|
50
78
|
|
51
|
-
it
|
79
|
+
it 'defaults to given adapter' do
|
52
80
|
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
|
53
81
|
|
54
82
|
# and should raise if already set
|
55
|
-
expect {
|
56
|
-
|
57
|
-
}.to raise_error(RuntimeError, "Adapter already set to QueueBus::Adapters::Data")
|
83
|
+
expect { QueueBus.adapter = :data }
|
84
|
+
.to raise_error(RuntimeError, 'Adapter already set to QueueBus::Adapters::Data')
|
58
85
|
end
|
59
86
|
|
60
|
-
context
|
87
|
+
context 'with a fresh load' do
|
61
88
|
before(:each) do
|
62
89
|
QueueBus.send(:reset)
|
63
90
|
end
|
64
91
|
|
65
|
-
|
66
|
-
|
67
|
-
|
92
|
+
context 'when set to adapter under test' do
|
93
|
+
before do
|
94
|
+
QueueBus.adapter = adapter_under_test_symbol
|
95
|
+
end
|
68
96
|
|
69
|
-
|
70
|
-
|
97
|
+
it 'sets to that adapter' do
|
98
|
+
expect(QueueBus.adapter).to be_a adapter_under_test_class
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when already set' do
|
103
|
+
before do
|
71
104
|
QueueBus.adapter = :data
|
72
|
-
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'raises' do
|
108
|
+
expect { QueueBus.adapter = :data }
|
109
|
+
.to raise_error(RuntimeError, 'Adapter already set to QueueBus::Adapters::Data')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'knows the adapter is set' do
|
113
|
+
expect(QueueBus).to have_adapter
|
114
|
+
end
|
73
115
|
end
|
74
116
|
|
75
|
-
|
117
|
+
context 'with a symbol' do
|
118
|
+
before do
|
119
|
+
QueueBus.adapter = :data
|
120
|
+
end
|
76
121
|
|
77
|
-
|
78
|
-
|
122
|
+
it 'looks up the known class' do
|
123
|
+
expect(QueueBus.adapter).to be_a QueueBus::Adapters::Data
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'with a custom adapter' do
|
128
|
+
let(:klass) do
|
129
|
+
Class.new(QueueBus::Adapters::Base) do
|
130
|
+
def enabled!
|
131
|
+
# no op
|
132
|
+
end
|
133
|
+
|
134
|
+
def redis
|
135
|
+
# no op
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
before do
|
141
|
+
QueueBus.adapter = klass.new
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'sets it to something else' do
|
145
|
+
expect(QueueBus.adapter).to be_a klass
|
146
|
+
end
|
79
147
|
end
|
80
|
-
end
|
81
148
|
|
149
|
+
context 'with a class' do
|
150
|
+
before do
|
151
|
+
QueueBus.adapter = QueueBus::Adapters::Data
|
152
|
+
end
|
82
153
|
|
154
|
+
it 'creates a new one' do
|
155
|
+
expect(QueueBus.adapter).to be_a QueueBus::Adapters::Data
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
83
159
|
end
|
data/spec/dispatch_spec.rb
CHANGED
@@ -1,76 +1,73 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Dispatch do
|
5
|
-
it
|
6
|
-
expect(Dispatch.new(
|
7
|
+
it 'should not start with any applications' do
|
8
|
+
expect(Dispatch.new('d').subscriptions.size).to eq(0)
|
7
9
|
end
|
8
|
-
|
9
|
-
it
|
10
|
-
dispatch = Dispatch.new(
|
11
|
-
dispatch.subscribe(
|
10
|
+
|
11
|
+
it 'should register code to run and execute it' do
|
12
|
+
dispatch = Dispatch.new('d')
|
13
|
+
dispatch.subscribe('my_event') do |attrs|
|
12
14
|
Runner1.run(attrs)
|
13
15
|
end
|
14
|
-
sub = dispatch.subscriptions.key(
|
16
|
+
sub = dispatch.subscriptions.key('my_event')
|
15
17
|
expect(sub.send(:executor).is_a?(Proc)).to eq(true)
|
16
18
|
|
17
19
|
expect(Runner.value).to eq(0)
|
18
|
-
dispatch.execute(
|
20
|
+
dispatch.execute('my_event', 'bus_event_type' => 'my_event', 'ok' => true)
|
19
21
|
expect(Runner1.value).to eq(1)
|
20
|
-
expect(Runner1.attributes).to eq(
|
21
|
-
|
22
|
+
expect(Runner1.attributes).to eq('bus_event_type' => 'my_event', 'ok' => true)
|
22
23
|
end
|
23
|
-
|
24
|
-
it
|
25
|
-
expect
|
26
|
-
Dispatch.new(
|
27
|
-
|
24
|
+
|
25
|
+
it 'should not crash if not there' do
|
26
|
+
expect do
|
27
|
+
Dispatch.new('d').execute('fdkjh', 'bus_event_type' => 'fdkjh')
|
28
|
+
end.not_to raise_error
|
28
29
|
end
|
29
|
-
|
30
|
-
describe
|
30
|
+
|
31
|
+
describe 'Top Level' do
|
31
32
|
before(:each) do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
QueueBus.dispatch('testit') do
|
34
|
+
subscribe 'event1' do |attributes|
|
35
|
+
Runner2.run(attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
subscribe 'event2' do
|
39
|
+
Runner2.run({})
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
high 'event3' do
|
43
|
+
Runner2.run({})
|
44
|
+
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should register and run" do
|
46
|
+
low /^patt.+ern/ do
|
47
|
+
Runner.run({})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should register and run' do
|
52
53
|
expect(Runner2.value).to eq(0)
|
53
|
-
QueueBus.dispatcher_execute(
|
54
|
+
QueueBus.dispatcher_execute('testit', 'event2', 'bus_event_type' => 'event2')
|
54
55
|
expect(Runner2.value).to eq(1)
|
55
|
-
QueueBus.dispatcher_execute(
|
56
|
+
QueueBus.dispatcher_execute('testit', 'event1', 'bus_event_type' => 'event1')
|
56
57
|
expect(Runner2.value).to eq(2)
|
57
|
-
QueueBus.dispatcher_execute(
|
58
|
+
QueueBus.dispatcher_execute('testit', 'event1', 'bus_event_type' => 'event1')
|
58
59
|
expect(Runner2.value).to eq(3)
|
59
60
|
end
|
60
|
-
|
61
|
-
it
|
62
|
-
dispatcher = QueueBus.dispatcher_by_key(
|
61
|
+
|
62
|
+
it 'should return the subscriptions' do
|
63
|
+
dispatcher = QueueBus.dispatcher_by_key('testit')
|
63
64
|
subs = dispatcher.subscriptions.all
|
64
|
-
tuples = subs.collect{ |sub| [sub.key, sub.queue_name]}
|
65
|
-
expect(tuples).to match_array([
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
])
|
65
|
+
tuples = subs.collect { |sub| [sub.key, sub.queue_name] }
|
66
|
+
expect(tuples).to match_array([%w[event1 testit_default],
|
67
|
+
%w[event2 testit_default],
|
68
|
+
%w[event3 testit_high],
|
69
|
+
['(?-mix:^patt.+ern)', 'testit_low']])
|
70
70
|
end
|
71
|
-
|
72
71
|
end
|
73
72
|
end
|
74
|
-
|
75
73
|
end
|
76
|
-
|
data/spec/driver_spec.rb
CHANGED
@@ -1,92 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Driver do
|
5
7
|
before(:each) do
|
6
|
-
Application.new(
|
7
|
-
Application.new(
|
8
|
-
Application.new(
|
8
|
+
Application.new('app1').subscribe(test_list(test_sub('event1'), test_sub('event2'), test_sub('event3')))
|
9
|
+
Application.new('app2').subscribe(test_list(test_sub('event2', 'other'), test_sub('event4', 'more')))
|
10
|
+
Application.new('app3').subscribe(test_list(test_sub('event[45]'), test_sub('event5'), test_sub('event6')))
|
9
11
|
Timecop.freeze
|
10
12
|
end
|
11
13
|
after(:each) do
|
12
14
|
Timecop.return
|
13
15
|
end
|
14
16
|
|
15
|
-
let(:bus_attrs) { {
|
17
|
+
let(:bus_attrs) { { 'bus_driven_at' => Time.now.to_i, 'bus_rider_class_name' => '::QueueBus::Rider', 'bus_class_proxy' => '::QueueBus::Rider' } }
|
16
18
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
expect(Driver.subscription_matches(
|
20
|
-
expect(Driver.subscription_matches(
|
19
|
+
describe '.subscription_matches' do
|
20
|
+
it 'return empty array when none' do
|
21
|
+
expect(Driver.subscription_matches('bus_event_type' => 'else').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
22
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
|
21
23
|
end
|
22
|
-
it
|
23
|
-
expect(Driver.subscription_matches(
|
24
|
-
expect(Driver.subscription_matches(
|
24
|
+
it 'should return a match' do
|
25
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event1').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app1', 'event1', 'default', '::QueueBus::Rider']])
|
26
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event6').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event6', 'default', '::QueueBus::Rider']])
|
25
27
|
end
|
26
|
-
it
|
27
|
-
expect(Driver.subscription_matches(
|
28
|
+
it 'should match multiple apps' do
|
29
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event2').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app1', 'event2', 'default', '::QueueBus::Rider'], ['app2', 'event2', 'other', '::QueueBus::Rider']])
|
28
30
|
end
|
29
|
-
it
|
30
|
-
expect(Driver.subscription_matches(
|
31
|
+
it 'should match multiple apps with patterns' do
|
32
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event4').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event[45]', 'default', '::QueueBus::Rider'], ['app2', 'event4', 'more', '::QueueBus::Rider']])
|
31
33
|
end
|
32
|
-
it
|
33
|
-
expect(Driver.subscription_matches(
|
34
|
+
it 'should match multiple events in same app' do
|
35
|
+
expect(Driver.subscription_matches('bus_event_type' => 'event5').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event[45]', 'default', '::QueueBus::Rider'], ['app3', 'event5', 'default', '::QueueBus::Rider']])
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
describe
|
38
|
-
let(:attributes) { {
|
39
|
+
describe '.perform' do
|
40
|
+
let(:attributes) { { 'x' => 'y', 'bus_class_proxy' => 'ResqueBus::Driver' } }
|
39
41
|
|
40
42
|
before(:each) do
|
41
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
42
|
-
expect(QueueBus.redis { |redis| redis.lpop(
|
43
|
-
expect(QueueBus.redis { |redis| redis.lpop(
|
44
|
-
expect(QueueBus.redis { |redis| redis.lpop(
|
43
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to eq([])
|
44
|
+
expect(QueueBus.redis { |redis| redis.lpop('queue:app1_default') }).to be_nil
|
45
|
+
expect(QueueBus.redis { |redis| redis.lpop('queue:app2_default') }).to be_nil
|
46
|
+
expect(QueueBus.redis { |redis| redis.lpop('queue:app3_default') }).to be_nil
|
45
47
|
end
|
46
48
|
|
47
|
-
it
|
48
|
-
Driver.perform(attributes.merge(
|
49
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
49
|
+
it 'should do nothing when empty' do
|
50
|
+
Driver.perform(attributes.merge('bus_event_type' => 'else'))
|
51
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to eq([])
|
50
52
|
end
|
51
53
|
|
52
|
-
it
|
53
|
-
expect(QueueBus.redis { |redis| redis.lpop(
|
54
|
-
Driver.perform(attributes.merge(
|
55
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
54
|
+
it 'should queue up the riders in redis' do
|
55
|
+
expect(QueueBus.redis { |redis| redis.lpop('queue:app1_default') }).to be_nil
|
56
|
+
Driver.perform(attributes.merge('bus_event_type' => 'event1'))
|
57
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['default'])
|
56
58
|
|
57
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop(
|
58
|
-
expect(hash[
|
59
|
-
expect(hash[
|
60
|
-
expect(JSON.parse(hash[
|
59
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
|
60
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
61
|
+
expect(hash['args'].size).to eq(1)
|
62
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app1', 'x' => 'y', 'bus_event_type' => 'event1', 'bus_rider_sub_key' => 'event1', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
|
61
63
|
end
|
62
64
|
|
63
|
-
it
|
64
|
-
Driver.perform(attributes.merge(
|
65
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
65
|
+
it 'should queue up to multiple' do
|
66
|
+
Driver.perform(attributes.merge('bus_event_type' => 'event4'))
|
67
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(%w[default more])
|
66
68
|
|
67
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop(
|
68
|
-
expect(hash[
|
69
|
-
expect(hash[
|
70
|
-
expect(JSON.parse(hash[
|
69
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:more') })
|
70
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
71
|
+
expect(hash['args'].size).to eq(1)
|
72
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app2', 'x' => 'y', 'bus_event_type' => 'event4', 'bus_rider_sub_key' => 'event4', 'bus_rider_queue' => 'more' }.merge(bus_attrs))
|
71
73
|
|
72
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop(
|
73
|
-
expect(hash[
|
74
|
-
expect(hash[
|
75
|
-
expect(JSON.parse(hash[
|
74
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
|
75
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
76
|
+
expect(hash['args'].size).to eq(1)
|
77
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event4', 'bus_rider_sub_key' => 'event[45]', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
|
76
78
|
end
|
77
79
|
|
78
|
-
it
|
79
|
-
Driver.perform(attributes.merge(
|
80
|
-
expect(QueueBus.redis { |redis| redis.smembers(
|
80
|
+
it 'should queue up to the same' do
|
81
|
+
Driver.perform(attributes.merge('bus_event_type' => 'event5'))
|
82
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['default'])
|
81
83
|
|
82
|
-
expect(QueueBus.redis { |redis| redis.llen(
|
84
|
+
expect(QueueBus.redis { |redis| redis.llen('queue:default') }).to eq(2)
|
83
85
|
|
84
|
-
pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop(
|
85
|
-
pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop(
|
86
|
+
pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
|
87
|
+
pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
|
86
88
|
|
87
|
-
pargs1 = JSON.parse(pop1[
|
88
|
-
pargs2 = JSON.parse(pop2[
|
89
|
-
if pargs1[
|
89
|
+
pargs1 = JSON.parse(pop1['args'].first)
|
90
|
+
pargs2 = JSON.parse(pop2['args'].first)
|
91
|
+
if pargs1['bus_rider_sub_key'] == 'event5'
|
90
92
|
hash1 = pop1
|
91
93
|
hash2 = pop2
|
92
94
|
args1 = pargs1
|
@@ -98,11 +100,11 @@ module QueueBus
|
|
98
100
|
args2 = pargs1
|
99
101
|
end
|
100
102
|
|
101
|
-
expect(hash1[
|
102
|
-
expect(args1).to eq({
|
103
|
+
expect(hash1['class']).to eq('QueueBus::Worker')
|
104
|
+
expect(args1).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event5', 'bus_rider_sub_key' => 'event5', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
|
103
105
|
|
104
|
-
expect(hash2[
|
105
|
-
expect(args2).to eq({
|
106
|
+
expect(hash2['class']).to eq('QueueBus::Worker')
|
107
|
+
expect(args2).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event5', 'bus_rider_sub_key' => 'event[45]', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end
|