queue-bus 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -0
  3. data/CHANGELOG.md +31 -0
  4. data/Gemfile +4 -2
  5. data/README.mdown +15 -3
  6. data/Rakefile +2 -0
  7. data/lib/queue-bus.rb +16 -12
  8. data/lib/queue_bus/adapters/base.rb +4 -2
  9. data/lib/queue_bus/adapters/data.rb +12 -11
  10. data/lib/queue_bus/application.rb +24 -16
  11. data/lib/queue_bus/config.rb +23 -2
  12. data/lib/queue_bus/dispatch.rb +14 -12
  13. data/lib/queue_bus/dispatchers.rb +12 -5
  14. data/lib/queue_bus/driver.rb +15 -10
  15. data/lib/queue_bus/heartbeat.rb +32 -30
  16. data/lib/queue_bus/local.rb +9 -9
  17. data/lib/queue_bus/matcher.rb +36 -27
  18. data/lib/queue_bus/publisher.rb +7 -5
  19. data/lib/queue_bus/publishing.rb +32 -24
  20. data/lib/queue_bus/rider.rb +26 -22
  21. data/lib/queue_bus/subscriber.rb +20 -14
  22. data/lib/queue_bus/subscription.rb +25 -15
  23. data/lib/queue_bus/subscription_list.rb +30 -12
  24. data/lib/queue_bus/task_manager.rb +25 -16
  25. data/lib/queue_bus/tasks.rb +35 -11
  26. data/lib/queue_bus/util.rb +11 -8
  27. data/lib/queue_bus/version.rb +3 -1
  28. data/lib/queue_bus/worker.rb +3 -2
  29. data/queue-bus.gemspec +19 -18
  30. data/spec/adapter/publish_at_spec.rb +28 -25
  31. data/spec/adapter/support.rb +7 -1
  32. data/spec/adapter_spec.rb +4 -2
  33. data/spec/application_spec.rb +138 -96
  34. data/spec/config_spec.rb +36 -0
  35. data/spec/dispatch_spec.rb +48 -51
  36. data/spec/driver_spec.rb +60 -58
  37. data/spec/heartbeat_spec.rb +26 -24
  38. data/spec/integration_spec.rb +41 -40
  39. data/spec/matcher_spec.rb +104 -102
  40. data/spec/publish_spec.rb +68 -46
  41. data/spec/publisher_spec.rb +3 -1
  42. data/spec/rider_spec.rb +16 -14
  43. data/spec/spec_helper.rb +2 -2
  44. data/spec/subscriber_spec.rb +227 -227
  45. data/spec/subscription_list_spec.rb +57 -31
  46. data/spec/subscription_spec.rb +37 -36
  47. data/spec/worker_spec.rb +17 -15
  48. metadata +12 -10
data/spec/spec_helper.rb CHANGED
@@ -12,8 +12,8 @@ module QueueBus
12
12
  @value ||= 0
13
13
  end
14
14
 
15
- def self.attributes
16
- @attributes
15
+ class << self
16
+ attr_reader :attributes
17
17
  end
18
18
 
19
19
  def self.run(attrs)
@@ -1,270 +1,270 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe QueueBus::Subscriber do
4
- let(:attributes) { {"x" => "y"} }
5
- let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i} }
3
+ require 'spec_helper'
6
4
 
7
- before(:each) do
8
- class SubscriberTest1
9
- include QueueBus::Subscriber
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
- application :my_thing
13
- subscribe :thing_filter, :x => "y"
14
- subscribe :event_sub
9
+ before(:each) do
10
+ class SubscriberTest1
11
+ include QueueBus::Subscriber
12
+ @queue = 'myqueue'
15
13
 
16
- def event_sub(attributes)
17
- QueueBus::Runner1.run(attributes)
18
- end
14
+ application :my_thing
15
+ subscribe :thing_filter, x: 'y'
16
+ subscribe :event_sub
19
17
 
20
- def thing_filter(attributes)
21
- QueueBus::Runner2.run(attributes)
22
- end
18
+ def event_sub(attributes)
19
+ QueueBus::Runner1.run(attributes)
23
20
  end
24
21
 
25
- class SubscriberTest2
26
- include QueueBus::Subscriber
27
- application :test2
28
- subscribe :test2, "value" => :present
29
- transform :make_an_int
22
+ def thing_filter(attributes)
23
+ QueueBus::Runner2.run(attributes)
24
+ end
25
+ end
30
26
 
31
- def self.make_an_int(attributes)
32
- attributes["value"].to_s.length
33
- end
27
+ class SubscriberTest2
28
+ include QueueBus::Subscriber
29
+ application :test2
30
+ subscribe :test2, 'value' => :present
31
+ transform :make_an_int
34
32
 
35
- def test2(int)
36
- QueueBus::Runner1.run("transformed"=>int)
37
- end
33
+ def self.make_an_int(attributes)
34
+ attributes['value'].to_s.length
38
35
  end
39
36
 
40
- module SubModule
41
- class SubscriberTest3
42
- include QueueBus::Subscriber
37
+ def test2(int)
38
+ QueueBus::Runner1.run('transformed' => int)
39
+ end
40
+ end
43
41
 
44
- subscribe_queue :sub_queue1, :test3, :bus_event_type => "the_event"
45
- subscribe_queue :sub_queue2, :the_event
46
- subscribe :other, :bus_event_type => "other_event"
42
+ module SubModule
43
+ class SubscriberTest3
44
+ include QueueBus::Subscriber
47
45
 
48
- def test3(attributes)
49
- QueueBus::Runner1.run(attributes)
50
- end
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
- def the_event(attributes)
53
- QueueBus::Runner2.run(attributes)
54
- end
50
+ def test3(attributes)
51
+ QueueBus::Runner1.run(attributes)
55
52
  end
56
53
 
57
- class SubscriberTest4
58
- include QueueBus::Subscriber
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
- Timecop.freeze
65
- QueueBus::TaskManager.new(false).subscribe!
66
- end
59
+ class SubscriberTest4
60
+ include QueueBus::Subscriber
67
61
 
68
- after(:each) do
69
- Timecop.return
62
+ subscribe_queue :sub_queue1, :test4
63
+ end
70
64
  end
71
65
 
72
- it "should have the application" do
73
- expect(SubscriberTest1.app_key).to eq("my_thing")
74
- expect(SubModule::SubscriberTest3.app_key).to eq("sub_module")
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
- it "should be able to transform the attributes" do
79
- dispatcher = QueueBus.dispatcher_by_key("test2")
80
- all = dispatcher.subscriptions.all
81
- expect(all.size).to eq(1)
70
+ after(:each) do
71
+ Timecop.return
72
+ end
82
73
 
83
- sub = all.first
84
- expect(sub.queue_name).to eq("test2_default")
85
- expect(sub.class_name).to eq("SubscriberTest2")
86
- expect(sub.key).to eq("SubscriberTest2.test2")
87
- expect(sub.matcher.filters).to eq({"value"=>"bus_special_value_present"})
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
- QueueBus::Driver.perform(attributes.merge("bus_event_type" => "something2", "value"=>"nice"))
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
- hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:test2_default") })
92
- expect(hash["class"]).to eq("QueueBus::Worker")
93
- expect(hash["args"].size).to eq(1)
94
- 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",
95
- "bus_event_type" => "something2", "value"=>"nice", "x"=>"y"}.merge(bus_attrs))
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
- expect(QueueBus::Runner1.value).to eq(0)
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
- expect(QueueBus::Runner1.attributes).to eq({"transformed" => 4})
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
- QueueBus::Driver.perform(attributes.merge("bus_event_type" => "something2", "value"=>"12"))
105
+ expect(QueueBus::Runner1.attributes).to eq('transformed' => 4)
107
106
 
108
- hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:test2_default") })
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
- expect(QueueBus::Runner1.value).to eq(1)
115
- expect(QueueBus::Runner2.value).to eq(0)
116
- QueueBus::Util.constantize(hash["class"]).perform(*hash["args"])
117
- expect(QueueBus::Runner1.value).to eq(2)
118
- expect(QueueBus::Runner2.value).to eq(0)
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
- expect(QueueBus::Runner1.attributes).to eq({"transformed" => 2})
121
- end
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
- 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)
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
- 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
208
- end
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
- 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
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
- 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)
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
- expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
267
- SubscriberTest1.perform(attributes)
268
- end
266
+ expect_any_instance_of(SubscriberTest1).to receive(:event_sub)
267
+ SubscriberTest1.perform(attributes)
269
268
  end
270
269
  end
270
+ end