21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-06 18:48:38 +02:00
chexpire/app/jobs/application_job.rb
Colin Darie 717cd3fac3
Wrap first sync in a common job
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.
2018-07-05 17:54:21 +02:00

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