Skip to content

Commit

Permalink
Merge pull request #1 from ryanbriones/lpoprpush-feature-flag
Browse files Browse the repository at this point in the history
Lpoprpush feature flag
  • Loading branch information
redsquirrel committed Mar 3, 2012
2 parents ba04a36 + 18e7818 commit 0ddf948
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def redis_id
end
end

# Enable/Disable lpoprpush
# Accepts:
# truthy value
def use_lpoprpush=(new_use_lpoprpush)
@use_lpoprpush = new_use_lpoprpush
end

# Returns truthy value of whether or not lpoprpush is enabled
def use_lpoprpush?
@use_lpoprpush ||= false
end

# The `before_first_fork` hook will be run in the **parent** process
# only once, before forking to run the first job. Be careful- any
# changes you make will be permanent for the lifespan of the
Expand Down Expand Up @@ -155,7 +167,7 @@ def push(queue, item)
#
# Returns a Ruby object.
def pop(queue)
decode lpoprpush("queue:#{queue}", "backup-queue:#{queue}")
decode(use_lpoprpush? ? lpoprpush("queue:#{queue}", "backup-queue:#{queue}") : redis.lpop("queue:#{queue}"))
end

# Removes a job _from_ queue and pushes it on _to_ another queue.
Expand Down
2 changes: 1 addition & 1 deletion lib/resque/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def perform
end

def do_perform(job, job_args)
Resque.remove_backup(queue, payload)
Resque.remove_backup(queue, payload) if Resque.use_lpoprpush?
job.perform(*job_args)
end

Expand Down
2 changes: 2 additions & 0 deletions test/job_hooks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,10 @@ def self.perform(ignored); end
end

test "the backup job is removed from the job's backup queue" do
Resque.stubs(:use_lpoprpush? => true)
Resque.redis.rpush("backup-queue:testqueue", Resque.encode("class" => "VerifyBackupRemovalJob", "args" => ["foo" => "bar"]))
perform_job("VerifyBackupRemovalJob", "foo" => "bar")
assert_equal [], Resque.redis.lrange("backup-queue:testqueue", 0, -1)
Resque.unstub(:use_lpoprpush?)
end
end
2 changes: 2 additions & 0 deletions test/resque_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@
end

test "can backup items when they are pulled off a queue" do
Resque.stubs(:use_lpoprpush? => true)
Resque.pop(:people)
assert_equal({ 'name' => 'chris' }, Resque.decode(Resque.redis.lpop("backup-queue:people")))
Resque.unstub(:use_lpoprpush?)
end

test "knows how big a queue is" do
Expand Down

0 comments on commit 0ddf948

Please sign in to comment.