Skip to content

Commit

Permalink
Use SHA1 for default #retry_identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
d11wtq committed Apr 13, 2012
1 parent cacf59e commit 0d5a94e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/resque/plugins/retry.rb
@@ -1,3 +1,5 @@
require 'digest/sha1'

module Resque
module Plugins

Expand Down Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d5a94e

Please sign in to comment.