worker_roulette 0.0.11 → 0.0.12
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.
@@ -4,7 +4,7 @@ module WorkerRoulette
|
|
4
4
|
def wait_for_work_orders(on_subscribe_callback = nil, &on_message_callback)
|
5
5
|
@redis_pubsub ||= WorkerRoulette.new_redis_pubsub #cannot use connection pool bc redis expects each obj to own its own pubsub connection for the life of the subscription
|
6
6
|
@redis_pubsub.on(:subscribe) {|channel, subscription_count| on_subscribe_callback.call(channel, subscription_count) if on_subscribe_callback}
|
7
|
-
@redis_pubsub.on(:message) {|channel, message| work_orders! {|work_orders| on_message_callback.call(work_orders, message, channel)} if on_message_callback}
|
7
|
+
@redis_pubsub.on(:message) {|channel, message| set_timer(on_message_callback); work_orders! {|work_orders| on_message_callback.call(work_orders, message, channel)} if on_message_callback}
|
8
8
|
@redis_pubsub.subscribe(@channel)
|
9
9
|
end
|
10
10
|
|
@@ -30,6 +30,15 @@ module WorkerRoulette
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
+
attr_reader :timer
|
34
|
+
def set_timer(on_message_callback)
|
35
|
+
return unless on_message_callback
|
36
|
+
@timer && @timer.cancel
|
37
|
+
@timer = EM::PeriodicTimer.new(rand(20..25)) do
|
38
|
+
work_orders! {|work_orders| on_message_callback.call(work_orders, nil, nil)}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
33
42
|
def self.lua_drain_work_orders
|
34
43
|
<<-HERE
|
35
44
|
local job_board_key = KEYS[1]
|
@@ -227,15 +227,49 @@ describe WorkerRoulette do
|
|
227
227
|
EM::Hiredis::PubsubClient.any_instance.should_receive(:close_connection).and_call_original
|
228
228
|
end
|
229
229
|
|
230
|
-
it "should periodically (random time between
|
231
|
-
|
232
|
-
|
233
|
-
|
230
|
+
it "should periodically (random time between 20 and 25 seconds?) poll the job board for new work, in case it missed a notification" do
|
231
|
+
EM::PeriodicTimer.should_receive(:new) {|time| time.should be_within(2.5).of(22.5)}
|
232
|
+
publish = proc {foreman.enqueue_work_order('foo')}
|
233
|
+
subject.wait_for_work_orders(publish) {done}
|
234
|
+
end
|
235
|
+
|
236
|
+
xit "should cancel the old timer when the on_message callback is called" do
|
237
|
+
publish = proc {foreman.enqueue_work_order('foo')}
|
238
|
+
subject.wait_for_work_orders(publish) do
|
239
|
+
subject.send(:timer).should_receive(:cancel).and_call_original
|
240
|
+
done
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should pull off work orders for more than one sender" do
|
245
|
+
tradesman = WorkerRoulette.a_tradesman('good_channel')
|
246
|
+
|
247
|
+
good_foreman = WorkerRoulette.a_foreman('good_foreman', 'good_channel')
|
248
|
+
lazy_foreman = WorkerRoulette.a_foreman('lazy_foreman', 'good_channel')
|
249
|
+
|
250
|
+
got_good = false
|
251
|
+
got_lazy = false
|
252
|
+
good_foreman.enqueue_work_order('do good work') do
|
253
|
+
tradesman.work_orders! do |r|
|
254
|
+
got_good = true
|
255
|
+
r.first['payload'].should == ('do good work')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
lazy_foreman.enqueue_work_order('just get it done') do
|
259
|
+
tradesman.work_orders! do |r|
|
260
|
+
got_lazy = true
|
261
|
+
r.first['payload'].should == ('just get it done')
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
done(0.2) {(got_good && got_lazy).should == true}
|
266
|
+
end
|
234
267
|
end
|
235
268
|
|
236
|
-
context "
|
237
|
-
|
238
|
-
|
269
|
+
context "Potential Ack Success/Failure for Processing Queues" do
|
270
|
+
xit "should not delete the messages from the queue until they have been processed succcesfully"
|
271
|
+
xit "should checkout a readlock for a queue and put it back when its done processing; lock should expire after 5 minutes?"
|
272
|
+
xit "should retry doing work on a queue 3 times if it is locked (ex backoff)"
|
239
273
|
end
|
240
274
|
|
241
275
|
context "Failure" do
|