mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure 0 is always the default for the individual exception counters in ActiveJob
Some adapters like Resque that use Redis, convert the Ruby hash with a default value, Hash.new(0), into a regular hash without a default value after serializing, storing and deserializing. This raises an error when we try to access a missing exception key. A simple solution is not to rely on the hash's default value, and provide a default as alternative when accessing it instead.
This commit is contained in:
parent
154057b4f7
commit
acbbd4ab8d
2 changed files with 3 additions and 3 deletions
|
@ -81,7 +81,7 @@ module ActiveJob
|
|||
@queue_name = self.class.queue_name
|
||||
@priority = self.class.priority
|
||||
@executions = 0
|
||||
@exception_executions = Hash.new(0)
|
||||
@exception_executions = {}
|
||||
end
|
||||
|
||||
# Returns a hash with the job data that can safely be passed to the
|
||||
|
|
|
@ -50,8 +50,8 @@ module ActiveJob
|
|||
def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: nil)
|
||||
rescue_from(*exceptions) do |error|
|
||||
# Guard against jobs that were persisted before we started having individual executions counters per retry_on
|
||||
self.exception_executions ||= Hash.new(0)
|
||||
self.exception_executions[exceptions.to_s] += 1
|
||||
self.exception_executions ||= {}
|
||||
self.exception_executions[exceptions.to_s] = (exception_executions[exceptions.to_s] || 0) + 1
|
||||
|
||||
if exception_executions[exceptions.to_s] < attempts
|
||||
retry_job wait: determine_delay(wait), queue: queue, priority: priority, error: error
|
||||
|
|
Loading…
Reference in a new issue