Module: Resque::Pertry::Retry
- Extended by:
- ActiveSupport::Concern
- Included in:
- Resque::Plugins::Pertry
- Defined in:
- lib/resque/pertry/retry.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #delay_before_retry(model) ⇒ Object
- #exception_whitelisted?(model, exception) ⇒ Boolean
- #max_attempt_reached?(model) ⇒ Boolean
-
#retry!(model, exception) ⇒ Object
Retry the job.
-
#retry?(model, exception) ⇒ Boolean
Checks if we can retry.
- #ttl_expired?(model) ⇒ Boolean
Instance Method Details
#delay_before_retry(model) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/resque/pertry/retry.rb', line 161 def delay_before_retry(model) if self.class.retry_delays self.class.retry_delays[ model.attempt - 1 ] else self.class.retry_delay || 0 end end |
#exception_whitelisted?(model, exception) ⇒ Boolean
137 138 139 140 141 142 |
# File 'lib/resque/pertry/retry.rb', line 137 def exception_whitelisted?(model, exception) # all exceptions are whitelisted implicitly if we didn't set the exception list return true unless self.class.retry_exceptions self.class.retry_exceptions.include?(exception.class) end |
#max_attempt_reached?(model) ⇒ Boolean
151 152 153 154 155 156 157 158 159 |
# File 'lib/resque/pertry/retry.rb', line 151 def max_attempt_reached?(model) if self.class.retry_attempts && self.class.retry_attempts < model.attempt true elsif self.class.retry_delays && self.class.retry_delays.size < model.attempt true else false end end |
#retry!(model, exception) ⇒ Object
Retry the job
128 129 130 131 132 133 134 135 |
# File 'lib/resque/pertry/retry.rb', line 128 def retry!(model, exception) return false unless retry?(model, exception) delay = delay_before_retry(model) return false unless delay Resque.enqueue_in(delay, self.class, payload) end |
#retry?(model, exception) ⇒ Boolean
Checks if we can retry
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/resque/pertry/retry.rb', line 112 def retry?(model, exception) # check the obvious return false unless model return false if model.finnished? # job has used up all it's allowed attempts return false if max_attempt_reached?(model) # job exception is not whitelisted for retries return false unless exception_whitelisted?(model, exception) # seems like we should be able to retry this job return true end |
#ttl_expired?(model) ⇒ Boolean
144 145 146 147 148 149 |
# File 'lib/resque/pertry/retry.rb', line 144 def ttl_expired?(model) # if we didn't set a ttl, it hasn't expired return false unless self.class.retry_ttl model.expired? end |