lib/resque/plugins/retry.rb in resque-retry-0.1.0 vs lib/resque/plugins/retry.rb in resque-retry-0.2.1
- old
+ new
@@ -61,12 +61,14 @@
def redis_retry_key(*args)
['resque-retry', name, identifier(*args)].compact.join(":").gsub(/\s/, '')
end
# Maximum number of retrys we can attempt to successfully perform the job.
- # A retry limit of 0 or below will retry forever.
#
+ # A retry limit of 0 will *never* retry.
+ # A retry limit of -1 or below will retry forever.
+ #
# @return [Fixnum]
def retry_limit
@retry_limit ||= 1
end
@@ -87,10 +89,18 @@
def retry_delay
@retry_delay ||= 0
end
# @abstract
+ # Number of seconds to sleep after job is requeued
+ #
+ # @return [Number] number of seconds to sleep
+ def sleep_after_requeue
+ @sleep_after_requeue ||= 0
+ end
+
+ # @abstract
# Modify the arguments used to retry the job. Use this to do something
# other than try the exact same job again.
#
# @return [Array] new job arguments
def args_for_retry(*args)
@@ -145,14 +155,17 @@
# Test if the retry limit has been reached.
#
# @return [Boolean]
def retry_limit_reached?
- if retry_limit > 0
- return true if retry_attempt >= retry_limit
+ if retry_limit == 0
+ true
+ elsif retry_limit > 0
+ true if retry_attempt >= retry_limit
+ else
+ false
end
- false
end
# Register a retry criteria check callback to be run before retrying
# the job again.
#
@@ -175,17 +188,18 @@
# @yieldreturn [Boolean] false == dont retry, true = can retry
def retry_criteria_check(&block)
retry_criteria_checks << block
end
- # Will retry the job.
+ # Retries the job.
def try_again(*args)
if retry_delay <= 0
# If the delay is 0, no point passing it through the scheduler
Resque.enqueue(self, *args_for_retry(*args))
else
Resque.enqueue_in(retry_delay, self, *args_for_retry(*args))
end
+ sleep(sleep_after_requeue) if sleep_after_requeue > 0
end
# Resque before_perform hook.
#
# Increments and sets the `@retry_attempt` count.