super-poller 0.2.0 → 0.2.3
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/lib/super_poller/starling_queue.rb +23 -0
- data/test/starling_queue_test.rb +8 -0
- metadata +2 -2
@@ -17,4 +17,27 @@ class SuperPoller::StarlingQueue
|
|
17
17
|
def fetch
|
18
18
|
@queue.fetch(@queue_name)
|
19
19
|
end
|
20
|
+
|
21
|
+
def length
|
22
|
+
@queue.sizeof(@queue_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def empty?
|
26
|
+
length.zero?
|
27
|
+
end
|
28
|
+
|
29
|
+
def any?
|
30
|
+
!empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def flush
|
34
|
+
@queue.delete(@queue_name)
|
35
|
+
rescue MemCache::MemCacheError => e
|
36
|
+
if e.message =~ /bad command line format/
|
37
|
+
STDERR.puts "WARNING: Server could not handle delete command. Falling back to the MUCH slower, and quite unreliable flush method. Consider using Reevoo Starling (http://github.com/reevoo/starling)"
|
38
|
+
@queue.flush(@queue_name)
|
39
|
+
else
|
40
|
+
raise
|
41
|
+
end
|
42
|
+
end
|
20
43
|
end
|
data/test/starling_queue_test.rb
CHANGED
@@ -27,6 +27,14 @@ class StarlingQueueTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal "second", queue.pop
|
28
28
|
end
|
29
29
|
|
30
|
+
should 'empty a queue' do
|
31
|
+
queue = StarlingQueue.new("TEST_QUEUE", ["localhost:#{STARLING_PORT}"])
|
32
|
+
queue.push("first")
|
33
|
+
queue.push("second")
|
34
|
+
queue.flush
|
35
|
+
assert queue.empty?
|
36
|
+
end
|
37
|
+
|
30
38
|
end
|
31
39
|
|
32
40
|
end
|