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