mirror of
https://github.com/Evolix/chexpire.git
synced 2024-07-01 21:42:52 +02:00
717cd3fac3
Sometimes, when the first job is executed milliseconds after the insert, the db would not return it. This way, we can safely perform another attempt.
23 lines
504 B
Ruby
23 lines
504 B
Ruby
class ApplicationJob < ActiveJob::Base
|
|
# from http://api.rubyonrails.org/classes/ActiveJob/Core.html
|
|
attr_writer :attempt_number
|
|
|
|
def attempt_number
|
|
@attempt_number ||= 0
|
|
end
|
|
|
|
def serialize
|
|
super.merge("attempt_number" => attempt_number + 1)
|
|
end
|
|
|
|
def deserialize(job_data)
|
|
super
|
|
self.attempt_number = job_data["attempt_number"]
|
|
end
|
|
|
|
rescue_from(Timeout::Error) do
|
|
raise if attempt_number > 5 # rubocop:disable Style/SignalException
|
|
retry_job(wait: 10)
|
|
end
|
|
end
|