2018-09-26 12:25:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AbortBeforeEnqueueJob < ActiveJob::Base
|
2019-11-28 17:40:24 -05:00
|
|
|
MyError = Class.new(StandardError)
|
|
|
|
|
|
|
|
before_enqueue :throw_or_raise
|
2019-11-28 07:56:49 -05:00
|
|
|
after_enqueue { self.flag = "after_enqueue" }
|
2019-11-28 17:40:24 -05:00
|
|
|
before_perform { throw(:abort) }
|
2019-11-28 07:56:49 -05:00
|
|
|
after_perform { self.flag = "after_perform" }
|
|
|
|
|
|
|
|
attr_accessor :flag
|
2018-09-26 12:25:20 -04:00
|
|
|
|
|
|
|
def perform
|
|
|
|
raise "This should never be called"
|
|
|
|
end
|
2019-11-28 17:40:24 -05:00
|
|
|
|
|
|
|
def throw_or_raise
|
|
|
|
if (arguments.first || :abort) == :abort
|
|
|
|
throw(:abort)
|
|
|
|
else
|
|
|
|
raise(MyError)
|
|
|
|
end
|
|
|
|
end
|
2018-09-26 12:25:20 -04:00
|
|
|
end
|