Permalink
Browse files

Use SHA1 for default #retry_identifier

  • Loading branch information...
1 parent cacf59e commit 0d5a94ebd8f952f78534cc4e7980224987924b2b @d11wtq committed Apr 13, 2012
Showing with 14 additions and 5 deletions.
  1. +3 −1 lib/resque/plugins/retry.rb
  2. +11 −4 test/retry_test.rb
View
4 lib/resque/plugins/retry.rb
@@ -1,3 +1,5 @@
+require 'digest/sha1'
+
module Resque
module Plugins
@@ -55,7 +57,7 @@ def inherited(subclass)
# @api public
def retry_identifier(*args)
args_string = args.join('-')
- args_string.empty? ? nil : args_string
+ args_string.empty? ? nil : Digest::SHA1.hexdigest(args_string)
end
# Builds the redis key to be used for keeping state of the job
View
15 test/retry_test.rb
@@ -1,5 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
+require 'digest/sha1'
+
class RetryTest < MiniTest::Unit::TestCase
def setup
Resque.redis.flushall
@@ -196,13 +198,18 @@ def test_delete_redis_key_after_final_failed_retry
end
def test_job_without_args_has_no_ending_colon_in_redis_key
- assert_equal 'resque-retry:GoodJob:yarrrr', GoodJob.redis_retry_key('yarrrr')
- assert_equal 'resque-retry:GoodJob:foo', GoodJob.redis_retry_key('foo')
+ assert_equal 'resque-retry:GoodJob:' << Digest::SHA1.hexdigest('yarrrr'), GoodJob.redis_retry_key('yarrrr')
+ assert_equal 'resque-retry:GoodJob:' << Digest::SHA1.hexdigest('foo'), GoodJob.redis_retry_key('foo')
assert_equal 'resque-retry:GoodJob', GoodJob.redis_retry_key
end
- def test_redis_retry_key_removes_whitespace
- assert_equal 'resque-retry:GoodJob:arg1-removespace', GoodJob.redis_retry_key('arg1', 'remove space')
+ def test_redis_retry_key_removes_whitespace_for_custom_retry_identifier
+ klass = Class.new(GoodJob) do
+ def self.retry_identifier(*args)
+ args.join(' ')
+ end
+ end
+ assert_equal 'resque-retry:abc', klass.redis_retry_key('a', 'b', 'c')
end
def test_retry_delay

0 comments on commit 0d5a94e

Please sign in to comment.