Module: Resque::Pertry::Retry::ClassMethods
- Defined in:
- lib/resque/pertry/retry.rb
Instance Method Summary collapse
-
#around_perform_pertry_00_retry(args = {}) ⇒ Object
Resque around_perform hook.
-
#on_failure_pertry_00_retry(exception, args = {}) ⇒ Object
Resque on_failure hook (job failed).
-
#reset_retry_properties ⇒ Object
Quickly reset all retry properties Useful if you have a base job class.
- #retry_attempts ⇒ Object
- #retry_delay ⇒ Object
- #retry_delays ⇒ Object
- #retry_exceptions ⇒ Object
- #retry_ttl ⇒ Object
-
#retryable? ⇒ Boolean
Check if we will retry this job on failure There has to be a constraint on the number of times we will retry a failing job or have a ttl, otherwise we could be retrying job endlessly.
-
#set_retry_attempts(count) ⇒ Object
Sets the maximum number of times we will retry.
-
#set_retry_delay(delay) ⇒ Object
Sets a number of seconds to wait before retrying.
-
#set_retry_delays(*delays) ⇒ Object
Sets a list of delays (list length will be the # of attempts).
-
#set_retry_exceptions(*exceptions) ⇒ Object
Sets a list of exceptions that we want to retry If none are set, we will retry every exceptions.
-
#set_retry_ttl(ttl) ⇒ Object
Sets the maximum time-to-live of the job, after which no attempts will ever be made.
Instance Method Details
#around_perform_pertry_00_retry(args = {}) ⇒ Object
Resque around_perform hook
90 91 92 93 94 |
# File 'lib/resque/pertry/retry.rb', line 90 def around_perform_pertry_00_retry(args = {}) ResquePertryPersistence.(self, args) yield end |
#on_failure_pertry_00_retry(exception, args = {}) ⇒ Object
Resque on_failure hook (job failed)
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/resque/pertry/retry.rb', line 97 def on_failure_pertry_00_retry(exception, args = {}) return unless retryable? ResquePertryPersistence.with_job(self, args) do |job_model| job = instance(args) unless job.retry!(job_model, exception) ResquePertryPersistence.fail_job(self, args) end end end |
#reset_retry_properties ⇒ Object
Quickly reset all retry properties Useful if you have a base job class
74 75 76 77 78 79 80 |
# File 'lib/resque/pertry/retry.rb', line 74 def reset_retry_properties self._retry_delays = nil self._retry_attempts = nil self._retry_delays = nil self._retry_ttl = nil self._retry_exceptions = nil end |
#retry_attempts ⇒ Object
49 50 51 |
# File 'lib/resque/pertry/retry.rb', line 49 def retry_attempts self._retry_attempts end |
#retry_delay ⇒ Object
28 29 30 |
# File 'lib/resque/pertry/retry.rb', line 28 def retry_delay self._retry_delay end |
#retry_delays ⇒ Object
39 40 41 |
# File 'lib/resque/pertry/retry.rb', line 39 def retry_delays self._retry_delays end |
#retry_exceptions ⇒ Object
68 69 70 |
# File 'lib/resque/pertry/retry.rb', line 68 def retry_exceptions self._retry_exceptions end |
#retry_ttl ⇒ Object
58 59 60 |
# File 'lib/resque/pertry/retry.rb', line 58 def retry_ttl self._retry_ttl end |
#retryable? ⇒ Boolean
Check if we will retry this job on failure There has to be a constraint on the number of times we will retry a failing job or have a ttl, otherwise we could be retrying job endlessly
85 86 87 |
# File 'lib/resque/pertry/retry.rb', line 85 def retryable? retry_attempts || retry_delays || retry_ttl end |
#set_retry_attempts(count) ⇒ Object
Sets the maximum number of times we will retry
44 45 46 47 |
# File 'lib/resque/pertry/retry.rb', line 44 def set_retry_attempts(count) self._retry_delays = nil self._retry_attempts = count == :clear ? nil : Integer(count) end |
#set_retry_delay(delay) ⇒ Object
Sets a number of seconds to wait before retrying
23 24 25 26 |
# File 'lib/resque/pertry/retry.rb', line 23 def set_retry_delay(delay) self._retry_delays = nil self._retry_delay = delay == :clear ? nil : Integer(delay) end |
#set_retry_delays(*delays) ⇒ Object
Sets a list of delays (list length will be the # of attempts)
33 34 35 36 37 |
# File 'lib/resque/pertry/retry.rb', line 33 def set_retry_delays(*delays) set_retry_attempts :clear set_retry_delay :clear self._retry_delays = Array(delays).map { |delay| Integer(delay) } end |
#set_retry_exceptions(*exceptions) ⇒ Object
Sets a list of exceptions that we want to retry If none are set, we will retry every exceptions
64 65 66 |
# File 'lib/resque/pertry/retry.rb', line 64 def set_retry_exceptions(*exceptions) self._retry_exceptions = Array(exceptions) end |
#set_retry_ttl(ttl) ⇒ Object
Sets the maximum time-to-live of the job, after which no attempts will ever be made
54 55 56 |
# File 'lib/resque/pertry/retry.rb', line 54 def set_retry_ttl(ttl) self._retry_ttl = ttl == :clear ? nil : Integer(ttl) end |