Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edbond/6520ff254dc00c24f5e8a295b121f29f to your computer and use it in GitHub Desktop.
Save edbond/6520ff254dc00c24f5e8a295b121f29f to your computer and use it in GitHub Desktop.
To enable ActiveJob to control retry
module ActiveJobRetryControlable
extend ActiveSupport::Concern
DEFAULT_RETRY_LIMIT = 5
class_methods do
def retry_limit(retry_limit)
@retry_limit = retry_limit
end
def load_retry_limit
@retry_limit || DEFAULT_RETRY_LIMIT
end
end
included do
attr_reader :attempt_number
def attempt_number
@attempt_number || 0
end
def serialize
super.merge("attempt_number" => attempt_number + 1)
end
def deserialize(job_data)
super
@attempt_number = (job_data["attempt_number"] || 1)
end
private
def retry_limit
self.class.load_retry_limit
end
def retry_limit_exceeded?
self.class.load_retry_limit
attempt_number > retry_limit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment