smq 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/smq/queue.rb +14 -8
  3. data/test/test_queue.rb +6 -0
  4. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/smq/queue.rb CHANGED
@@ -44,20 +44,26 @@ module SMQ
44
44
  delete_queue_items
45
45
  end
46
46
 
47
- def clear_completed!
48
- delete_queue_items "completed_at IS NOT NULL"
47
+ def clear_completed!(limit = nil)
48
+ delete_queue_items "completed_at IS NOT NULL", limit
49
49
  end
50
- def clear_successful!
51
- delete_queue_items "completed_at IS NOT NULL AND failed_at IS NULL"
50
+ def clear_successful!(limit = nil)
51
+ delete_queue_items "completed_at IS NOT NULL AND failed_at IS NULL", limit
52
52
  end
53
- def clear_failed!
54
- delete_queue_items "completed_at IS NOT NULL AND failed_at IS NOT NULL"
53
+ def clear_failed!(limit = nil)
54
+ delete_queue_items "completed_at IS NOT NULL AND failed_at IS NOT NULL", limit
55
55
  end
56
56
 
57
57
  private
58
58
 
59
- def delete_queue_items(where = nil)
60
- SMQ::Message.delete_all(["queue = ? #{where ? 'AND ' + where : ''}", @name])
59
+ def delete_queue_items(where = nil, limit = nil)
60
+ # delete_all doesn't support a :limit clause, so we have to fake it
61
+ msg = SMQ::Message.find(:first, :offset => limit) if !limit.nil?
62
+ if (msg.nil?)
63
+ SMQ::Message.delete_all(["queue = ? #{where ? 'AND ' + where : ''}", @name])
64
+ else
65
+ SMQ::Message.delete_all(["queue = ? AND id < ? #{where ? 'AND ' + where : ''}", @name, msg.id])
66
+ end
61
67
  end
62
68
 
63
69
  end
data/test/test_queue.rb CHANGED
@@ -57,6 +57,12 @@ class QueueTest < Test::Unit::TestCase
57
57
  assert_equal 1, SMQ::Message.count(:conditions => ["queue = ?", @queue.name])
58
58
  end
59
59
 
60
+ def test_clearing_completed_should_limit_correctly
61
+ populate_and_ack_all_but_fail_one
62
+ @queue.clear_completed! 1
63
+ assert_equal 4, SMQ::Message.count(:conditions => ["queue = ?", @queue.name])
64
+ end
65
+
60
66
  def test_clearing_failures_should_not_touch_successful_messages
61
67
  populate_and_ack_all_but_fail_one
62
68
  @queue.clear_failed!
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Blair
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-10 00:00:00 +00:00
17
+ date: 2010-03-16 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency