Skip to content

Commit 2139b66

Browse files
committed
don't allow pushing to a Queue after it's been destroyed
1 parent ee8c764 commit 2139b66

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/resque/queue.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
require 'mutex_m'
55

66
module Resque
7+
###
8+
# Exception raised when trying to access a queue that's already destroyed
9+
class QueueDestroyed < RuntimeError; end
10+
711
###
812
# A queue interface that quacks like Queue from Ruby's stdlib.
913
class Queue
@@ -25,7 +29,10 @@ def initialize name, redis, coder = Marshal
2529
end
2630

2731
# Add +object+ to the queue
32+
# If trying to push to an already destroyed queue, it will raise a Resque::QueueDestroyed exception
2833
def push object
34+
raise QueueDestroyed if destroyed?
35+
2936
synchronize do
3037
@redis.rpush @redis_name, encode(object)
3138
end

test/redis_queue_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ def == other
108108
assert queue1.destroyed?
109109
end
110110

111+
it "can't push to queue after destroying it" do
112+
queue1 = q
113+
x = Thing.new
114+
queue1 << x
115+
queue1.destroy
116+
117+
assert_raise Resque::QueueDestroyed do
118+
queue1 << x
119+
end
120+
end
121+
111122
def q
112123
Resque::Queue.new 'foo', Resque.redis
113124
end

0 commit comments

Comments
 (0)