2016-07-30 04:54:55 +08:00
|
|
|
require_relative '../support/job_buffer'
|
|
|
|
require 'active_support/core_ext/integer/inflections'
|
|
|
|
|
2016-08-02 07:09:16 +08:00
|
|
|
class DefaultsError < StandardError; end
|
|
|
|
class ShortWaitTenAttemptsError < StandardError; end
|
|
|
|
class DiscardableError < StandardError; end
|
2016-07-30 04:54:55 +08:00
|
|
|
|
|
|
|
class RetryJob < ActiveJob::Base
|
2016-08-02 07:09:16 +08:00
|
|
|
retry_on DefaultsError
|
|
|
|
retry_on ShortWaitTenAttemptsError, wait: 1.second, attempts: 10
|
|
|
|
discard_on DiscardableError
|
2016-07-30 04:54:55 +08:00
|
|
|
|
|
|
|
def perform(raising, attempts)
|
|
|
|
if executions < attempts
|
|
|
|
JobBuffer.add("Raised #{raising} for the #{executions.ordinalize} time")
|
|
|
|
raise raising.constantize
|
|
|
|
else
|
|
|
|
JobBuffer.add("Successfully completed job")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|