super-poller 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tom Lea