2014-08-29 04:28:07 -04:00
|
|
|
require_relative '../support/job_buffer'
|
|
|
|
|
2014-05-22 14:35:02 -04:00
|
|
|
class RescueJob < ActiveJob::Base
|
2014-05-22 19:14:13 -04:00
|
|
|
class OtherError < StandardError; end
|
|
|
|
|
|
|
|
rescue_from(ArgumentError) do
|
2014-08-17 09:23:24 -04:00
|
|
|
JobBuffer.add('rescued from ArgumentError')
|
2014-05-22 14:35:02 -04:00
|
|
|
arguments[0] = "DIFFERENT!"
|
2014-08-25 10:34:50 -04:00
|
|
|
retry_job
|
2014-05-22 14:35:02 -04:00
|
|
|
end
|
|
|
|
|
2014-08-17 16:48:44 -04:00
|
|
|
rescue_from(ActiveJob::DeserializationError) do |e|
|
|
|
|
JobBuffer.add('rescued from DeserializationError')
|
2015-11-03 09:54:34 -05:00
|
|
|
JobBuffer.add("DeserializationError original exception was #{e.cause.class.name}")
|
2014-08-17 16:48:44 -04:00
|
|
|
end
|
|
|
|
|
2014-05-22 14:35:02 -04:00
|
|
|
def perform(person = "david")
|
2014-05-22 19:14:13 -04:00
|
|
|
case person
|
|
|
|
when "david"
|
|
|
|
raise ArgumentError, "Hair too good"
|
|
|
|
when "other"
|
|
|
|
raise OtherError
|
2014-05-22 14:35:02 -04:00
|
|
|
else
|
2014-08-17 09:23:24 -04:00
|
|
|
JobBuffer.add('performed beautifully')
|
2014-05-22 14:35:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|