2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
require_relative "../support/job_buffer"
|
2014-08-29 04:28:07 -04:00
|
|
|
|
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
|
2016-08-06 12:41:18 -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|
|
2016-08-06 12:41:18 -04:00
|
|
|
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"
|
2017-03-27 19:16:50 -04:00
|
|
|
raise OtherError, "Bad hair"
|
2014-05-22 14:35:02 -04:00
|
|
|
else
|
2016-08-06 12:41:18 -04:00
|
|
|
JobBuffer.add("performed beautifully")
|
2014-05-22 14:35:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|