Permalink
Browse files

Don't have ending `:` in the redis key if were not using any argument…

…s or nil is returned from the identifier.
  • Loading branch information...
1 parent 65975cf commit a2283e0b29fcf0f933c114d67424737cb61ef99a @lantins committed May 6, 2010
Showing with 16 additions and 7 deletions.
  1. +1 −0 LICENSE
  2. +2 −1 lib/resque/plugins/retry.rb
  3. +12 −6 test/retry_test.rb
  4. +1 −0 test/test_jobs.rb
View
@@ -1,4 +1,5 @@
Copyright (c) 2010 Luke Antins
+Copyright (c) 2010 Ryan Carver
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -45,7 +45,8 @@ module Retry
# @param [Array] args job arguments
# @return [String] job identifier
def identifier(*args)
- args.join('-')
+ args_string = args.join('-')
+ args_string.empty? ? nil : args_string
end
##
View
@@ -108,28 +108,34 @@ def test_do_not_retry_if_failed_and_exception_does_not_allow_retry
def test_delete_redis_key_when_job_is_successful
Resque.enqueue(GoodJob, 'arg1')
- assert_equal nil, Resque.redis.get('resque-retry:GoodJob:arg1')
+ assert_equal nil, Resque.redis.get(GoodJob.redis_retry_key('arg1'))
perform_next_job(@worker)
- assert_equal nil, Resque.redis.get('resque-retry:GoodJob:arg1')
+ assert_equal nil, Resque.redis.get(GoodJob.redis_retry_key('arg1'))
end
def test_delete_redis_key_after_final_failed_retry
Resque.enqueue(FailFiveTimesJob, 'yarrrr')
- assert_equal nil, Resque.redis.get('resque-retry:FailFiveTimesJob:yarrrr')
+ assert_equal nil, Resque.redis.get(FailFiveTimesJob.redis_retry_key('yarrrr'))
perform_next_job(@worker)
- assert_equal '0', Resque.redis.get('resque-retry:FailFiveTimesJob:yarrrr')
+ assert_equal '0', Resque.redis.get(FailFiveTimesJob.redis_retry_key('yarrrr'))
perform_next_job(@worker)
- assert_equal '1', Resque.redis.get('resque-retry:FailFiveTimesJob:yarrrr')
+ assert_equal '1', Resque.redis.get(FailFiveTimesJob.redis_retry_key('yarrrr'))
5.times do
perform_next_job(@worker)
end
- assert_equal nil, Resque.redis.get('resque-retry:FailFiveTimesJob:yarrrr')
+ assert_equal nil, Resque.redis.get(FailFiveTimesJob.redis_retry_key('yarrrr'))
assert_equal 5, Resque.info[:failed], 'failed jobs'
assert_equal 6, Resque.info[:processed], 'processed job'
assert_equal 0, Resque.info[:pending], 'pending jobs'
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', GoodJob.redis_retry_key
+ end
end
View
@@ -3,6 +3,7 @@
AnotherCustomException = Class.new(StandardError)
class GoodJob
+ extend Resque::Plugins::Retry
@queue = :testing
def self.perform(*args)
end

0 comments on commit a2283e0

Please sign in to comment.