Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only one argument for has_remaining_performs_key?

  • Loading branch information...
commit 547dc078c3fba9666361fcdcda08a0db4924dd39 1 parent 9f07f29
@julienXX authored
View
6 lib/resque/plugins/waiting_room.rb
@@ -17,7 +17,7 @@ def waiting_room_redis_key
def before_perform_waiting_room(*args)
key = waiting_room_redis_key
- if has_remaining_performs_key?(key, @max_performs)
+ if has_remaining_performs_key?(key)
performs_left = Resque.redis.decrby(key, 1).to_i
if performs_left < 1
@@ -27,9 +27,9 @@ def before_perform_waiting_room(*args)
end
end
- def has_remaining_performs_key?(key, number_of_performs)
+ def has_remaining_performs_key?(key)
# Redis SETNX: sets the keys if it doesn't exist, returns true if key was created
- new_key = Resque.redis.setnx(key, number_of_performs - 1)
+ new_key = Resque.redis.setnx(key, @max_performs - 1)
Resque.redis.expire(key, @period) if new_key
return !new_key
View
15 spec/resque/plugins/waiting_room_spec.rb
@@ -56,30 +56,33 @@
context "has_remaining_performs_key?" do
it "should set a redis key" do
Resque.redis.should_receive(:setnx)
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key, 10)
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
end
- it "should expire the redis key with period" do
+ it "should expire the redis key" do
Resque.redis.should_receive(:setnx).and_return(true)
Resque.redis.should_receive(:expire)
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key, 10)
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
end
it "should not re-expire the redis key if it is already created" do
+ Resque.redis.should_receive(:setnx).and_return(true)
+ Resque.redis.should_receive(:expire)
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
Resque.redis.should_receive(:setnx).and_return(false)
Resque.redis.should_not_receive(:expire)
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key, 10)
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key)
end
it "should return false if the key is new" do
Resque.redis.should_receive(:setnx).and_return(true)
Resque.redis.should_receive(:expire)
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key, 10).should == false
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key).should == false
end
it "should return true if the key was already created" do
Resque.redis.should_receive(:setnx).and_return(false)
- DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key, 10).should == true
+ DummyJob.has_remaining_performs_key?(DummyJob.waiting_room_redis_key).should == true
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.