sidekiq-bus 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE +20 -0
- data/README.mdown +264 -0
- data/Rakefile +2 -0
- data/lib/sidekiq-bus.rb +9 -0
- data/lib/sidekiq_bus/adapter.rb +28 -0
- data/lib/sidekiq_bus/tasks.rb +93 -0
- data/lib/sidekiq_bus/version.rb +3 -0
- data/sidekiq-bus.gemspec +27 -0
- data/spec/adapter/support.rb +14 -0
- data/spec/adapter_spec.rb +14 -0
- data/spec/application_spec.rb +152 -0
- data/spec/config_spec.rb +83 -0
- data/spec/dispatch_spec.rb +76 -0
- data/spec/driver_spec.rb +109 -0
- data/spec/heartbeat_spec.rb +44 -0
- data/spec/integration_spec.rb +53 -0
- data/spec/matcher_spec.rb +143 -0
- data/spec/publish_spec.rb +98 -0
- data/spec/publisher_spec.rb +7 -0
- data/spec/rider_spec.rb +39 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/subscriber_spec.rb +270 -0
- data/spec/subscription_list_spec.rb +43 -0
- data/spec/subscription_spec.rb +53 -0
- data/spec/worker_spec.rb +32 -0
- metadata +167 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe QueueBus::Subscriber do
|
4
|
+
let(:attributes) { {"x" => "y"} }
|
5
|
+
let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i} }
|
6
|
+
|
7
|
+
before(:each) do
|
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
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
Timecop.return
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have the application" do
|
73
|
+
SubscriberTest1.app_key.should == "my_thing"
|
74
|
+
SubModule::SubscriberTest3.app_key.should == "sub_module"
|
75
|
+
SubModule::SubscriberTest4.app_key.should == "sub_module"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be able to transform the attributes" do
|
79
|
+
dispatcher = QueueBus.dispatcher_by_key("test2")
|
80
|
+
all = dispatcher.subscriptions.all
|
81
|
+
all.size.should == 1
|
82
|
+
|
83
|
+
sub = all.first
|
84
|
+
sub.queue_name.should == "test2_default"
|
85
|
+
sub.class_name.should == "SubscriberTest2"
|
86
|
+
sub.key.should == "SubscriberTest2.test2"
|
87
|
+
sub.matcher.filters.should == {"value"=>"bus_special_value_present"}
|
88
|
+
|
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}
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
it "should put in a different queue" do
|
125
|
+
dispatcher = QueueBus.dispatcher_by_key("sub_module")
|
126
|
+
all = dispatcher.subscriptions.all
|
127
|
+
all.size.should == 4
|
128
|
+
|
129
|
+
sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.test3"}.first
|
130
|
+
sub.queue_name.should == "sub_queue1"
|
131
|
+
sub.class_name.should == "SubModule::SubscriberTest3"
|
132
|
+
sub.key.should == "SubModule::SubscriberTest3.test3"
|
133
|
+
sub.matcher.filters.should == {"bus_event_type"=>"the_event"}
|
134
|
+
|
135
|
+
sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.the_event"}.first
|
136
|
+
sub.queue_name.should == "sub_queue2"
|
137
|
+
sub.class_name.should == "SubModule::SubscriberTest3"
|
138
|
+
sub.key.should == "SubModule::SubscriberTest3.the_event"
|
139
|
+
sub.matcher.filters.should == {"bus_event_type"=>"the_event"}
|
140
|
+
|
141
|
+
sub = all.select{ |s| s.key == "SubModule::SubscriberTest3.other"}.first
|
142
|
+
sub.queue_name.should == "sub_module_default"
|
143
|
+
sub.class_name.should == "SubModule::SubscriberTest3"
|
144
|
+
sub.key.should == "SubModule::SubscriberTest3.other"
|
145
|
+
sub.matcher.filters.should == {"bus_event_type"=>"other_event"}
|
146
|
+
|
147
|
+
sub = all.select{ |s| s.key == "SubModule::SubscriberTest4.test4"}.first
|
148
|
+
sub.queue_name.should == "sub_queue1"
|
149
|
+
sub.class_name.should == "SubModule::SubscriberTest4"
|
150
|
+
sub.key.should == "SubModule::SubscriberTest4.test4"
|
151
|
+
sub.matcher.filters.should == {"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
|
+
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
|
178
|
+
end
|
179
|
+
|
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
|
+
sub.queue_name.should == "myqueue"
|
186
|
+
sub.class_name.should == "SubscriberTest1"
|
187
|
+
sub.key.should == "SubscriberTest1.event_sub"
|
188
|
+
sub.matcher.filters.should == {"bus_event_type"=>"event_sub"}
|
189
|
+
|
190
|
+
sub = all.select{ |s| s.key == "SubscriberTest1.thing_filter"}.first
|
191
|
+
sub.queue_name.should == "myqueue"
|
192
|
+
sub.class_name.should == "SubscriberTest1"
|
193
|
+
sub.key.should == "SubscriberTest1.thing_filter"
|
194
|
+
sub.matcher.filters.should == {"x"=>"y"}
|
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
|
250
|
+
end
|
251
|
+
|
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
|
+
SubscriberTest1.any_instance.should_receive(:event_sub)
|
256
|
+
SubscriberTest1.perform(attributes)
|
257
|
+
end
|
258
|
+
it "should set the timezone and locale if present" do
|
259
|
+
defined?(I18n).should be_nil
|
260
|
+
Time.respond_to?(:zone).should eq(false)
|
261
|
+
|
262
|
+
stub_const("I18n", Class.new)
|
263
|
+
I18n.should_receive(:locale=).with("en")
|
264
|
+
Time.should_receive(:zone=).with("PST")
|
265
|
+
|
266
|
+
SubscriberTest1.any_instance.should_receive(:event_sub)
|
267
|
+
SubscriberTest1.perform(attributes)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module QueueBus
|
4
|
+
describe SubscriptionList do
|
5
|
+
describe ".from_redis" do
|
6
|
+
it "should return from attributes" do
|
7
|
+
mult = {"event_one" => {"class" => "MyClass", "queue_name" => "default", "key" => "event_one", "matcher" => {"bus_event_type" => "event_one"}},
|
8
|
+
"event_two" => {"class" => "MyClass", "queue_name" => "else", "key" => "event_two", "matcher" => {"bus_event_type" => "event_two"}}}
|
9
|
+
|
10
|
+
list = SubscriptionList.from_redis(mult)
|
11
|
+
list.size.should == 2
|
12
|
+
one = list.key("event_one")
|
13
|
+
two = list.key("event_two")
|
14
|
+
|
15
|
+
one.key.should == "event_one"
|
16
|
+
one.key.should == "event_one"
|
17
|
+
one.queue_name.should == "default"
|
18
|
+
one.class_name.should == "MyClass"
|
19
|
+
one.matcher.filters.should == {"bus_event_type" => "event_one"}
|
20
|
+
|
21
|
+
two.key.should == "event_two"
|
22
|
+
two.key.should == "event_two"
|
23
|
+
two.queue_name.should == "else"
|
24
|
+
two.class_name.should == "MyClass"
|
25
|
+
two.matcher.filters.should == {"bus_event_type" => "event_two"}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#to_redis" do
|
30
|
+
it "should generate what to store" do
|
31
|
+
list = SubscriptionList.new
|
32
|
+
list.add(Subscription.new("default", "key1", "MyClass", {"bus_event_type" => "event_one"}))
|
33
|
+
list.add(Subscription.new("else_ok", "key2", "MyClass", {"bus_event_type" => "event_two"}))
|
34
|
+
|
35
|
+
hash = list.to_redis
|
36
|
+
hash.should == { "key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
|
37
|
+
"key2" => {"queue_name" => "else_ok", "key" => "key2", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_two"}}
|
38
|
+
}
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module QueueBus
|
4
|
+
describe Subscription do
|
5
|
+
it "should normalize the queue name" do
|
6
|
+
Subscription.new("test", "my_event", "MyClass", {}, nil).queue_name.should == "test"
|
7
|
+
Subscription.new("tes t", "my_event", "MyClass", {}, nil).queue_name.should == "tes_t"
|
8
|
+
Subscription.new("t%s", "my_event", "MyClass", {}, nil).queue_name.should == "t_s"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".register" do
|
12
|
+
it "should take in args from dispatcher" do
|
13
|
+
executor = Proc.new { |attributes| }
|
14
|
+
sub = Subscription.register("queue_name", "mykey", "MyClass", {"bus_event_type" => "my_event"}, executor)
|
15
|
+
sub.send(:executor).should == executor
|
16
|
+
sub.matcher.filters.should == {"bus_event_type" => "my_event"}
|
17
|
+
sub.queue_name.should == "queue_name"
|
18
|
+
sub.key.should == "mykey"
|
19
|
+
sub.class_name.should == "MyClass"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#execute!" do
|
24
|
+
it "should call the executor with the attributes" do
|
25
|
+
exec = Object.new
|
26
|
+
exec.should_receive(:call)
|
27
|
+
|
28
|
+
sub = Subscription.new("x", "y", "ClassName", {}, exec)
|
29
|
+
sub.execute!({"ok" => true})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_redis" do
|
34
|
+
it "should return what to store for this subscription" do
|
35
|
+
sub = Subscription.new("queue_one", "xyz", "ClassName", {"bus_event_type" => "my_event"}, nil)
|
36
|
+
sub.to_redis.should == {"queue_name" => "queue_one", "key" => "xyz", "class" => "ClassName", "matcher" => {"bus_event_type" => "my_event"}}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#matches?" do
|
41
|
+
it "should do pattern stuff" do
|
42
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "one").should == true
|
43
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "onex").should == false
|
44
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "^one.*$"}).matches?("bus_event_type" => "onex").should == true
|
45
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.*"}).matches?("bus_event_type" => "onex").should == true
|
46
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "onex").should == true
|
47
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "one").should == true
|
48
|
+
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "\\"}).matches?("bus_event_type" => "one").should == false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
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
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-bus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Leonard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: queue-bus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '4.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: timecop
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: json_pure
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: A simple event bus on top of Resque. Publish and subscribe to events
|
90
|
+
as they occur through a queue.
|
91
|
+
email:
|
92
|
+
- brian@bleonard.com
|
93
|
+
executables: []
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rbenv-version"
|
99
|
+
- ".rspec"
|
100
|
+
- Gemfile
|
101
|
+
- MIT-LICENSE
|
102
|
+
- README.mdown
|
103
|
+
- Rakefile
|
104
|
+
- lib/sidekiq-bus.rb
|
105
|
+
- lib/sidekiq_bus/adapter.rb
|
106
|
+
- lib/sidekiq_bus/tasks.rb
|
107
|
+
- lib/sidekiq_bus/version.rb
|
108
|
+
- sidekiq-bus.gemspec
|
109
|
+
- spec/adapter/support.rb
|
110
|
+
- spec/adapter_spec.rb
|
111
|
+
- spec/application_spec.rb
|
112
|
+
- spec/config_spec.rb
|
113
|
+
- spec/dispatch_spec.rb
|
114
|
+
- spec/driver_spec.rb
|
115
|
+
- spec/heartbeat_spec.rb
|
116
|
+
- spec/integration_spec.rb
|
117
|
+
- spec/matcher_spec.rb
|
118
|
+
- spec/publish_spec.rb
|
119
|
+
- spec/publisher_spec.rb
|
120
|
+
- spec/rider_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/subscriber_spec.rb
|
123
|
+
- spec/subscription_list_spec.rb
|
124
|
+
- spec/subscription_spec.rb
|
125
|
+
- spec/worker_spec.rb
|
126
|
+
homepage: https://github.com/queue-bus/sidekiq-bus
|
127
|
+
licenses: []
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project: sidekiq-bus
|
145
|
+
rubygems_version: 2.2.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: A simple event bus on top of Resque
|
149
|
+
test_files:
|
150
|
+
- spec/adapter/support.rb
|
151
|
+
- spec/adapter_spec.rb
|
152
|
+
- spec/application_spec.rb
|
153
|
+
- spec/config_spec.rb
|
154
|
+
- spec/dispatch_spec.rb
|
155
|
+
- spec/driver_spec.rb
|
156
|
+
- spec/heartbeat_spec.rb
|
157
|
+
- spec/integration_spec.rb
|
158
|
+
- spec/matcher_spec.rb
|
159
|
+
- spec/publish_spec.rb
|
160
|
+
- spec/publisher_spec.rb
|
161
|
+
- spec/rider_spec.rb
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
- spec/subscriber_spec.rb
|
164
|
+
- spec/subscription_list_spec.rb
|
165
|
+
- spec/subscription_spec.rb
|
166
|
+
- spec/worker_spec.rb
|
167
|
+
has_rdoc:
|