queue-bus 0.9.0 → 0.12.0
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/CHANGELOG.md +26 -0
- data/Gemfile +4 -2
- data/README.mdown +15 -3
- data/Rakefile +2 -0
- data/lib/queue-bus.rb +16 -12
- data/lib/queue_bus/adapters/base.rb +4 -2
- data/lib/queue_bus/adapters/data.rb +12 -11
- data/lib/queue_bus/application.rb +57 -22
- data/lib/queue_bus/config.rb +22 -1
- 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 +32 -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 +25 -16
- data/lib/queue_bus/tasks.rb +28 -15
- 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 -18
- 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 +138 -96
- data/spec/config_spec.rb +35 -0
- 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 +68 -46
- data/spec/publisher_spec.rb +3 -1
- data/spec/rider_spec.rb +16 -14
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +57 -31
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +17 -15
- metadata +7 -6
data/spec/spec_helper.rb
CHANGED
data/spec/subscriber_spec.rb
CHANGED
@@ -1,270 +1,270 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
let(:attributes) { {"x" => "y"} }
|
5
|
-
let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i} }
|
3
|
+
require 'spec_helper'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@queue = "myqueue"
|
5
|
+
describe QueueBus::Subscriber do
|
6
|
+
let(:attributes) { { 'x' => 'y' } }
|
7
|
+
let(:bus_attrs) { { 'bus_driven_at' => Time.now.to_i } }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
before(:each) do
|
10
|
+
class SubscriberTest1
|
11
|
+
include QueueBus::Subscriber
|
12
|
+
@queue = 'myqueue'
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
application :my_thing
|
15
|
+
subscribe :thing_filter, x: 'y'
|
16
|
+
subscribe :event_sub
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
18
|
+
def event_sub(attributes)
|
19
|
+
QueueBus::Runner1.run(attributes)
|
23
20
|
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
transform :make_an_int
|
22
|
+
def thing_filter(attributes)
|
23
|
+
QueueBus::Runner2.run(attributes)
|
24
|
+
end
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
class SubscriberTest2
|
28
|
+
include QueueBus::Subscriber
|
29
|
+
application :test2
|
30
|
+
subscribe :test2, 'value' => :present
|
31
|
+
transform :make_an_int
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
33
|
+
def self.make_an_int(attributes)
|
34
|
+
attributes['value'].to_s.length
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
def test2(int)
|
38
|
+
QueueBus::Runner1.run('transformed' => int)
|
39
|
+
end
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
module SubModule
|
43
|
+
class SubscriberTest3
|
44
|
+
include QueueBus::Subscriber
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
subscribe_queue :sub_queue1, :test3, bus_event_type: 'the_event'
|
47
|
+
subscribe_queue :sub_queue2, :the_event
|
48
|
+
subscribe :other, bus_event_type: 'other_event'
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
def test3(attributes)
|
51
|
+
QueueBus::Runner1.run(attributes)
|
55
52
|
end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
subscribe_queue :sub_queue1, :test4
|
54
|
+
def the_event(attributes)
|
55
|
+
QueueBus::Runner2.run(attributes)
|
61
56
|
end
|
62
57
|
end
|
63
58
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
59
|
+
class SubscriberTest4
|
60
|
+
include QueueBus::Subscriber
|
67
61
|
|
68
|
-
|
69
|
-
|
62
|
+
subscribe_queue :sub_queue1, :test4
|
63
|
+
end
|
70
64
|
end
|
71
65
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
expect(SubModule::SubscriberTest4.app_key).to eq("sub_module")
|
76
|
-
end
|
66
|
+
Timecop.freeze
|
67
|
+
QueueBus::TaskManager.new(false).subscribe!
|
68
|
+
end
|
77
69
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
expect(all.size).to eq(1)
|
70
|
+
after(:each) do
|
71
|
+
Timecop.return
|
72
|
+
end
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
74
|
+
it 'should have the application' do
|
75
|
+
expect(SubscriberTest1.app_key).to eq('my_thing')
|
76
|
+
expect(SubModule::SubscriberTest3.app_key).to eq('sub_module')
|
77
|
+
expect(SubModule::SubscriberTest4.app_key).to eq('sub_module')
|
78
|
+
end
|
88
79
|
|
89
|
-
|
80
|
+
it 'should be able to transform the attributes' do
|
81
|
+
dispatcher = QueueBus.dispatcher_by_key('test2')
|
82
|
+
all = dispatcher.subscriptions.all
|
83
|
+
expect(all.size).to eq(1)
|
90
84
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
sub = all.first
|
86
|
+
expect(sub.queue_name).to eq('test2_default')
|
87
|
+
expect(sub.class_name).to eq('SubscriberTest2')
|
88
|
+
expect(sub.key).to eq('SubscriberTest2.test2')
|
89
|
+
expect(sub.matcher.filters).to eq('value' => 'bus_special_value_present')
|
96
90
|
|
97
|
-
|
98
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
99
|
-
QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
|
100
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
101
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
91
|
+
QueueBus::Driver.perform(attributes.merge('bus_event_type' => 'something2', 'value' => 'nice'))
|
102
92
|
|
103
|
-
|
93
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:test2_default') })
|
94
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
95
|
+
expect(hash['args'].size).to eq(1)
|
96
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'SubscriberTest2', 'bus_rider_app_key' => 'test2', 'bus_rider_sub_key' => 'SubscriberTest2.test2', 'bus_rider_queue' => 'test2_default', 'bus_rider_class_name' => 'SubscriberTest2',
|
97
|
+
'bus_event_type' => 'something2', 'value' => 'nice', 'x' => 'y' }.merge(bus_attrs))
|
104
98
|
|
99
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
100
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
101
|
+
QueueBus::Util.constantize(hash['class']).perform(*hash['args'])
|
102
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
103
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
105
104
|
|
106
|
-
|
105
|
+
expect(QueueBus::Runner1.attributes).to eq('transformed' => 4)
|
107
106
|
|
108
|
-
|
109
|
-
expect(hash["class"]).to eq("QueueBus::Worker")
|
110
|
-
expect(hash["args"].size).to eq(1)
|
111
|
-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest2", "bus_rider_app_key"=>"test2", "bus_rider_sub_key"=>"SubscriberTest2.test2", "bus_rider_queue" => "test2_default", "bus_rider_class_name"=>"SubscriberTest2",
|
112
|
-
"bus_event_type" => "something2", "value"=>"12", "x"=>"y"}.merge(bus_attrs))
|
107
|
+
QueueBus::Driver.perform(attributes.merge('bus_event_type' => 'something2', 'value' => '12'))
|
113
108
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
109
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:test2_default') })
|
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' => 'SubscriberTest2', 'bus_rider_app_key' => 'test2', 'bus_rider_sub_key' => 'SubscriberTest2.test2', 'bus_rider_queue' => 'test2_default', 'bus_rider_class_name' => 'SubscriberTest2',
|
113
|
+
'bus_event_type' => 'something2', 'value' => '12', 'x' => 'y' }.merge(bus_attrs))
|
119
114
|
|
120
|
-
|
121
|
-
|
115
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
116
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
117
|
+
QueueBus::Util.constantize(hash['class']).perform(*hash['args'])
|
118
|
+
expect(QueueBus::Runner1.value).to eq(2)
|
119
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
122
120
|
|
121
|
+
expect(QueueBus::Runner1.attributes).to eq('transformed' => 2)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should put in a different queue' do
|
125
|
+
dispatcher = QueueBus.dispatcher_by_key('sub_module')
|
126
|
+
all = dispatcher.subscriptions.all
|
127
|
+
expect(all.size).to eq(4)
|
128
|
+
|
129
|
+
sub = all.select { |s| s.key == 'SubModule::SubscriberTest3.test3' }.first
|
130
|
+
expect(sub.queue_name).to eq('sub_queue1')
|
131
|
+
expect(sub.class_name).to eq('SubModule::SubscriberTest3')
|
132
|
+
expect(sub.key).to eq('SubModule::SubscriberTest3.test3')
|
133
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'the_event')
|
134
|
+
|
135
|
+
sub = all.select { |s| s.key == 'SubModule::SubscriberTest3.the_event' }.first
|
136
|
+
expect(sub.queue_name).to eq('sub_queue2')
|
137
|
+
expect(sub.class_name).to eq('SubModule::SubscriberTest3')
|
138
|
+
expect(sub.key).to eq('SubModule::SubscriberTest3.the_event')
|
139
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'the_event')
|
140
|
+
|
141
|
+
sub = all.select { |s| s.key == 'SubModule::SubscriberTest3.other' }.first
|
142
|
+
expect(sub.queue_name).to eq('sub_module_default')
|
143
|
+
expect(sub.class_name).to eq('SubModule::SubscriberTest3')
|
144
|
+
expect(sub.key).to eq('SubModule::SubscriberTest3.other')
|
145
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'other_event')
|
146
|
+
|
147
|
+
sub = all.select { |s| s.key == 'SubModule::SubscriberTest4.test4' }.first
|
148
|
+
expect(sub.queue_name).to eq('sub_queue1')
|
149
|
+
expect(sub.class_name).to eq('SubModule::SubscriberTest4')
|
150
|
+
expect(sub.key).to eq('SubModule::SubscriberTest4.test4')
|
151
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'test4')
|
152
|
+
|
153
|
+
QueueBus::Driver.perform(attributes.merge('bus_event_type' => 'the_event'))
|
154
|
+
|
155
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:sub_queue1') })
|
156
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
157
|
+
expect(hash['args'].size).to eq(1)
|
158
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'SubModule::SubscriberTest3', 'bus_rider_app_key' => 'sub_module', 'bus_rider_sub_key' => 'SubModule::SubscriberTest3.test3', 'bus_rider_queue' => 'sub_queue1', 'bus_rider_class_name' => 'SubModule::SubscriberTest3',
|
159
|
+
'bus_event_type' => 'the_event', 'x' => 'y' }.merge(bus_attrs))
|
160
|
+
|
161
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
162
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
163
|
+
QueueBus::Util.constantize(hash['class']).perform(*hash['args'])
|
164
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
165
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
166
|
+
|
167
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:sub_queue2') })
|
168
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
169
|
+
expect(hash['args'].size).to eq(1)
|
170
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'SubModule::SubscriberTest3', 'bus_rider_app_key' => 'sub_module', 'bus_rider_sub_key' => 'SubModule::SubscriberTest3.the_event', 'bus_rider_queue' => 'sub_queue2', 'bus_rider_class_name' => 'SubModule::SubscriberTest3',
|
171
|
+
'bus_event_type' => 'the_event', 'x' => 'y' }.merge(bus_attrs))
|
172
|
+
|
173
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
174
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
175
|
+
QueueBus::Util.constantize(hash['class']).perform(*hash['args'])
|
176
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
177
|
+
expect(QueueBus::Runner2.value).to eq(1)
|
178
|
+
end
|
123
179
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
QueueBus::Driver.perform(attributes.merge("bus_event_type" => "the_event"))
|
154
|
-
|
155
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:sub_queue1") })
|
156
|
-
expect(hash["class"]).to eq("QueueBus::Worker")
|
157
|
-
expect(hash["args"].size).to eq(1)
|
158
|
-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.test3", "bus_rider_queue" => "sub_queue1", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
|
159
|
-
"bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs))
|
160
|
-
|
161
|
-
expect(QueueBus::Runner1.value).to eq(0)
|
162
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
163
|
-
QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
|
164
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
165
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
166
|
-
|
167
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:sub_queue2") })
|
168
|
-
expect(hash["class"]).to eq("QueueBus::Worker")
|
169
|
-
expect(hash["args"].size).to eq(1)
|
170
|
-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubModule::SubscriberTest3", "bus_rider_app_key"=>"sub_module", "bus_rider_sub_key"=>"SubModule::SubscriberTest3.the_event", "bus_rider_queue" => "sub_queue2", "bus_rider_class_name"=>"SubModule::SubscriberTest3",
|
171
|
-
"bus_event_type" => "the_event", "x" => "y"}.merge(bus_attrs))
|
172
|
-
|
173
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
174
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
175
|
-
QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
|
176
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
177
|
-
expect(QueueBus::Runner2.value).to eq(1)
|
180
|
+
it 'should subscribe to default and attributes' do
|
181
|
+
dispatcher = QueueBus.dispatcher_by_key('my_thing')
|
182
|
+
all = dispatcher.subscriptions.all
|
183
|
+
|
184
|
+
sub = all.select { |s| s.key == 'SubscriberTest1.event_sub' }.first
|
185
|
+
expect(sub.queue_name).to eq('myqueue')
|
186
|
+
expect(sub.class_name).to eq('SubscriberTest1')
|
187
|
+
expect(sub.key).to eq('SubscriberTest1.event_sub')
|
188
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'event_sub')
|
189
|
+
|
190
|
+
sub = all.select { |s| s.key == 'SubscriberTest1.thing_filter' }.first
|
191
|
+
expect(sub.queue_name).to eq('myqueue')
|
192
|
+
expect(sub.class_name).to eq('SubscriberTest1')
|
193
|
+
expect(sub.key).to eq('SubscriberTest1.thing_filter')
|
194
|
+
expect(sub.matcher.filters).to eq('x' => 'y')
|
195
|
+
|
196
|
+
QueueBus::Driver.perform(attributes.merge('bus_event_type' => 'event_sub'))
|
197
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['myqueue'])
|
198
|
+
|
199
|
+
pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:myqueue') })
|
200
|
+
pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:myqueue') })
|
201
|
+
|
202
|
+
if JSON.parse(pop1['args'].first)['bus_rider_sub_key'] == 'SubscriberTest1.thing_filter'
|
203
|
+
hash1 = pop1
|
204
|
+
hash2 = pop2
|
205
|
+
else
|
206
|
+
hash1 = pop2
|
207
|
+
hash2 = pop1
|
178
208
|
end
|
179
209
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
210
|
+
expect(hash1['class']).to eq('QueueBus::Worker')
|
211
|
+
expect(JSON.parse(hash1['args'].first)).to eq({ 'bus_class_proxy' => 'SubscriberTest1', 'bus_rider_app_key' => 'my_thing', 'bus_rider_sub_key' => 'SubscriberTest1.thing_filter', 'bus_rider_queue' => 'myqueue', 'bus_rider_class_name' => 'SubscriberTest1',
|
212
|
+
'bus_event_type' => 'event_sub', 'x' => 'y' }.merge(bus_attrs))
|
213
|
+
|
214
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
215
|
+
expect(QueueBus::Runner2.value).to eq(0)
|
216
|
+
QueueBus::Util.constantize(hash1['class']).perform(*hash1['args'])
|
217
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
218
|
+
expect(QueueBus::Runner2.value).to eq(1)
|
219
|
+
|
220
|
+
expect(hash2['class']).to eq('QueueBus::Worker')
|
221
|
+
expect(hash2['args'].size).to eq(1)
|
222
|
+
expect(JSON.parse(hash2['args'].first)).to eq({ 'bus_class_proxy' => 'SubscriberTest1', 'bus_rider_app_key' => 'my_thing', 'bus_rider_sub_key' => 'SubscriberTest1.event_sub', 'bus_rider_queue' => 'myqueue', 'bus_rider_class_name' => 'SubscriberTest1',
|
223
|
+
'bus_event_type' => 'event_sub', 'x' => 'y' }.merge(bus_attrs))
|
224
|
+
|
225
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
226
|
+
expect(QueueBus::Runner2.value).to eq(1)
|
227
|
+
QueueBus::Util.constantize(hash2['class']).perform(*hash2['args'])
|
228
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
229
|
+
expect(QueueBus::Runner2.value).to eq(1)
|
230
|
+
|
231
|
+
QueueBus::Driver.perform(attributes.merge('bus_event_type' => 'event_sub_other'))
|
232
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['myqueue'])
|
233
|
+
|
234
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:myqueue') })
|
235
|
+
expect(hash['class']).to eq('QueueBus::Worker')
|
236
|
+
expect(hash['args'].size).to eq(1)
|
237
|
+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'SubscriberTest1', 'bus_rider_app_key' => 'my_thing', 'bus_rider_sub_key' => 'SubscriberTest1.thing_filter', 'bus_rider_queue' => 'myqueue', 'bus_rider_class_name' => 'SubscriberTest1',
|
238
|
+
'bus_event_type' => 'event_sub_other', 'x' => 'y' }.merge(bus_attrs))
|
239
|
+
|
240
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
241
|
+
expect(QueueBus::Runner2.value).to eq(1)
|
242
|
+
QueueBus::Util.constantize(hash['class']).perform(*hash['args'])
|
243
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
244
|
+
expect(QueueBus::Runner2.value).to eq(2)
|
245
|
+
|
246
|
+
QueueBus::Driver.perform({ 'x' => 'z' }.merge('bus_event_type' => 'event_sub_other'))
|
247
|
+
expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['myqueue'])
|
248
|
+
|
249
|
+
expect(QueueBus.redis { |redis| redis.lpop('queue:myqueue') }).to be_nil
|
250
|
+
end
|
209
251
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
expect(QueueBus::Runner2.value).to eq(0)
|
216
|
-
QueueBus::Util.constantize(hash1["class"]).perform(*hash1["args"])
|
217
|
-
expect(QueueBus::Runner1.value).to eq(0)
|
218
|
-
expect(QueueBus::Runner2.value).to eq(1)
|
219
|
-
|
220
|
-
expect(hash2["class"]).to eq("QueueBus::Worker")
|
221
|
-
expect(hash2["args"].size).to eq(1)
|
222
|
-
expect(JSON.parse(hash2["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.event_sub", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
|
223
|
-
"bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs))
|
224
|
-
|
225
|
-
expect(QueueBus::Runner1.value).to eq(0)
|
226
|
-
expect(QueueBus::Runner2.value).to eq(1)
|
227
|
-
QueueBus::Util.constantize(hash2["class"]).perform(*hash2["args"])
|
228
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
229
|
-
expect(QueueBus::Runner2.value).to eq(1)
|
230
|
-
|
231
|
-
QueueBus::Driver.perform(attributes.merge("bus_event_type" => "event_sub_other"))
|
232
|
-
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["myqueue"])
|
233
|
-
|
234
|
-
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:myqueue") })
|
235
|
-
expect(hash["class"]).to eq("QueueBus::Worker")
|
236
|
-
expect(hash["args"].size).to eq(1)
|
237
|
-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "SubscriberTest1", "bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
|
238
|
-
"bus_event_type" => "event_sub_other", "x" => "y"}.merge(bus_attrs))
|
239
|
-
|
240
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
241
|
-
expect(QueueBus::Runner2.value).to eq(1)
|
242
|
-
QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
|
243
|
-
expect(QueueBus::Runner1.value).to eq(1)
|
244
|
-
expect(QueueBus::Runner2.value).to eq(2)
|
245
|
-
|
246
|
-
QueueBus::Driver.perform({"x"=>"z"}.merge("bus_event_type" => "event_sub_other"))
|
247
|
-
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["myqueue"])
|
248
|
-
|
249
|
-
expect(QueueBus.redis { |redis| redis.lpop("queue:myqueue") }).to be_nil
|
252
|
+
describe '.perform' do
|
253
|
+
let(:attributes) { { 'bus_rider_sub_key' => 'SubscriberTest1.event_sub', 'bus_locale' => 'en', 'bus_timezone' => 'PST' } }
|
254
|
+
it 'should call the method based on key' do
|
255
|
+
expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
|
256
|
+
SubscriberTest1.perform(attributes)
|
250
257
|
end
|
258
|
+
it 'should set the timezone and locale if present' do
|
259
|
+
expect(defined?(I18n)).to be_nil
|
260
|
+
expect(Time.respond_to?(:zone)).to eq(false)
|
251
261
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
|
256
|
-
SubscriberTest1.perform(attributes)
|
257
|
-
end
|
258
|
-
it "should set the timezone and locale if present" do
|
259
|
-
expect(defined?(I18n)).to be_nil
|
260
|
-
expect(Time.respond_to?(:zone)).to eq(false)
|
261
|
-
|
262
|
-
stub_const("I18n", Class.new)
|
263
|
-
expect(I18n).to receive(:locale=).with("en")
|
264
|
-
expect(Time).to receive(:zone=).with("PST")
|
262
|
+
stub_const('I18n', Class.new)
|
263
|
+
expect(I18n).to receive(:locale=).with('en')
|
264
|
+
expect(Time).to receive(:zone=).with('PST')
|
265
265
|
|
266
|
-
|
267
|
-
|
268
|
-
end
|
266
|
+
expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
|
267
|
+
SubscriberTest1.perform(attributes)
|
269
268
|
end
|
270
269
|
end
|
270
|
+
end
|