Discard the job with no attempts to retry, if the exception is raised. This is useful when the subject of the job, like an Active Record, is no longer available, and the job is thus no longer relevant.
You can also pass a block that'll be invoked. This block is yielded with the job instance as the first and the error instance as the second parameter.
class SearchIndexingJob < ActiveJob::Base discard_on ActiveJob::DeserializationError discard_on(CustomAppException) do |job, error| ExceptionNotifier.caught(error) end def perform(record) # Will raise ActiveJob::DeserializationError if the record can't be deserialized # Might raise CustomAppException for something domain specific end end
class UserNotFoundJob < ActiveJob::Base discard_on ActiveRecord::RecordNotFound def perform(user_id) @user = User.find(user_id) @user.do_some_thing end end