fairway 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/fairway/connection.rb +4 -0
- data/lib/fairway/queue.rb +5 -1
- data/lib/fairway/scripts.rb +4 -0
- data/lib/fairway/version.rb +1 -1
- data/redis/fairway_destroy.lua +29 -0
- data/spec/lib/fairway/connection_spec.rb +13 -0
- data/spec/lib/fairway/queue_spec.rb +64 -0
- data/spec/lib/fairway/scripts_spec.rb +11 -1
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/lib/fairway/connection.rb
CHANGED
data/lib/fairway/queue.rb
CHANGED
@@ -18,7 +18,7 @@ module Fairway
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def length
|
21
|
-
redis.mget(unique_queues.map{|q| "#{q}:length" }).sum
|
21
|
+
redis.mget(unique_queues.map{|q| "#{q}:length" }).map(&:to_i).sum
|
22
22
|
end
|
23
23
|
|
24
24
|
def peek
|
@@ -44,6 +44,10 @@ module Fairway
|
|
44
44
|
queue
|
45
45
|
end
|
46
46
|
|
47
|
+
def destroy
|
48
|
+
scripts.fairway_destroy(unique_queues)
|
49
|
+
end
|
50
|
+
|
47
51
|
def redis
|
48
52
|
@connection.redis
|
49
53
|
end
|
data/lib/fairway/scripts.rb
CHANGED
data/lib/fairway/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
local namespace = KEYS[1];
|
2
|
+
|
3
|
+
local k = function (queue, subkey)
|
4
|
+
return namespace .. queue .. ':' .. subkey;
|
5
|
+
end
|
6
|
+
|
7
|
+
-- Multiple queues can be passed through
|
8
|
+
-- fairway_destroy. We'll loop through all
|
9
|
+
-- provided queues, and delete related keys
|
10
|
+
-- for each queue.
|
11
|
+
for i, queue in ipairs(ARGV) do
|
12
|
+
local priorities = k(queue, 'priorities');
|
13
|
+
local active_facets = k(queue, 'active_facets');
|
14
|
+
local round_robin = k(queue, 'facet_queue');
|
15
|
+
local facet_pool = k(queue, 'facet_pool');
|
16
|
+
local length = k(queue, 'length');
|
17
|
+
|
18
|
+
local facets = redis.call('smembers', active_facets);
|
19
|
+
|
20
|
+
for i = 1, #facets, 1 do
|
21
|
+
redis.call('del', k(queue, facets[i]));
|
22
|
+
end
|
23
|
+
|
24
|
+
redis.call('del', priorities);
|
25
|
+
redis.call('del', active_facets);
|
26
|
+
redis.call('del', round_robin);
|
27
|
+
redis.call('del', facet_pool);
|
28
|
+
redis.call('del', length);
|
29
|
+
end
|
@@ -78,6 +78,19 @@ module Fairway
|
|
78
78
|
redis.llen("myqueue:facet_queue").should == 0
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
context "unregistering a queue" do
|
83
|
+
before do
|
84
|
+
Fairway.config.register_queue("myqueue")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "stops adding messages to the queue" do
|
88
|
+
connection.deliver(message)
|
89
|
+
connection.unregister_queue("myqueue")
|
90
|
+
connection.deliver(message)
|
91
|
+
redis.llen("myqueue:1").should == 1
|
92
|
+
end
|
93
|
+
end
|
81
94
|
end
|
82
95
|
end
|
83
96
|
end
|
@@ -306,6 +306,70 @@ module Fairway
|
|
306
306
|
end
|
307
307
|
end
|
308
308
|
|
309
|
+
describe "#destroy" do
|
310
|
+
let(:facet) { Facet.new(queue, 1) }
|
311
|
+
|
312
|
+
it "removes all queued messages" do
|
313
|
+
connection.deliver(message)
|
314
|
+
queue.length.should == 1
|
315
|
+
facet.length.should == 1
|
316
|
+
queue.destroy
|
317
|
+
queue.length.should == 0
|
318
|
+
facet.length.should == 0
|
319
|
+
end
|
320
|
+
|
321
|
+
it "removes all facets" do
|
322
|
+
connection.deliver(message)
|
323
|
+
queue.active_facets.length.should == 1
|
324
|
+
queue.destroy
|
325
|
+
queue.active_facets.length.should == 0
|
326
|
+
end
|
327
|
+
|
328
|
+
it "removes any redis keys related to the queue" do
|
329
|
+
connection.deliver(message)
|
330
|
+
|
331
|
+
connection.redis.keys("myqueue:*").length.should > 0
|
332
|
+
|
333
|
+
queue.destroy
|
334
|
+
|
335
|
+
connection.redis.keys("myqueue:*").length.should == 0
|
336
|
+
end
|
337
|
+
|
338
|
+
context "multiple queues" do
|
339
|
+
let(:queue) { Queue.new(connection, "myqueue2", "myqueue1") }
|
340
|
+
|
341
|
+
before do
|
342
|
+
Fairway.config.register_queue("myqueue1", "event:1")
|
343
|
+
Fairway.config.register_queue("myqueue2", "event:2")
|
344
|
+
|
345
|
+
connection.deliver(message.merge(topic: "event:1"))
|
346
|
+
connection.deliver(message.merge(topic: "event:2"))
|
347
|
+
end
|
348
|
+
|
349
|
+
it "destroys both queues" do
|
350
|
+
queue.length.should == 2
|
351
|
+
queue.destroy
|
352
|
+
queue.length.should == 0
|
353
|
+
end
|
354
|
+
|
355
|
+
it "removes all facets" do
|
356
|
+
queue.active_facets.length.should == 1
|
357
|
+
queue.destroy
|
358
|
+
queue.active_facets.length.should == 0
|
359
|
+
end
|
360
|
+
|
361
|
+
it "removes any redis keys related both queues" do
|
362
|
+
connection.redis.keys("myqueue1:*").length.should > 0
|
363
|
+
connection.redis.keys("myqueue2:*").length.should > 0
|
364
|
+
|
365
|
+
queue.destroy
|
366
|
+
|
367
|
+
connection.redis.keys("myqueue1:*").length.should == 0
|
368
|
+
connection.redis.keys("myqueue2:*").length.should == 0
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
309
373
|
describe "equality" do
|
310
374
|
it "should equal queues with same connection and queue names" do
|
311
375
|
Queue.new(connection, "a", "b", "c").should == Queue.new(connection, "a", "b", "c")
|
@@ -19,7 +19,17 @@ module Fairway
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "#
|
22
|
+
describe "#unregister_queue" do
|
23
|
+
let(:scripts) { Scripts.new(Redis.new, "foo") }
|
24
|
+
|
25
|
+
it "removes the queue and channel from the hash of registered queues" do
|
26
|
+
scripts.register_queue("name", "channel")
|
27
|
+
scripts.unregister_queue("name")
|
28
|
+
Redis.new.hgetall("foo:registered_queues").should == {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#registered_queues" do
|
23
33
|
let(:scripts) { Scripts.new(Redis.new, "foo") }
|
24
34
|
|
25
35
|
it "returns hash of all registered queues and their channels" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fairway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/fairway/sidekiq/fetch.rb
|
104
104
|
- lib/fairway/version.rb
|
105
105
|
- redis/fairway_deliver.lua
|
106
|
+
- redis/fairway_destroy.lua
|
106
107
|
- redis/fairway_peek.lua
|
107
108
|
- redis/fairway_priority.lua
|
108
109
|
- redis/fairway_pull.lua
|