Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Lpoprpush feature flag #1

Merged
merged 1 commit into from

2 participants

@ryanbriones

Add a feature flag for lpoprpush to make pulling into defunkt/resque less risky initially but become the standard after time and testing.

Pulling this into your branch should automatically update your pull request in defunkt/resque

@redsquirrel redsquirrel merged commit 0ddf948 into redsquirrel:lpoprpush
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
14 lib/resque.rb
@@ -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
@@ -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.
View
2  lib/resque/job.rb
@@ -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
View
2  test/job_hooks_test.rb
@@ -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
View
2  test/resque_test.rb
@@ -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
Something went wrong with that request. Please try again.