Skip to content

Commit

Permalink
Discard jobs that fail to deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Nov 15, 2023
1 parent 67f7685 commit 39dab08
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/jobs/application_job.rb
@@ -1,7 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
def perform_now(*)
super
rescue ActiveJob::DeserializationError => e
raise unless e.cause.is_a?(ActiveRecord::RecordNotFound)
end
end
7 changes: 7 additions & 0 deletions app/jobs/mail_delivery_job.rb
@@ -0,0 +1,7 @@
class MailDeliveryJob < ActionMailer::MailDeliveryJob
def perform_now(*)
super
rescue ActiveJob::DeserializationError => e
raise unless e.cause.is_a?(ActiveRecord::RecordNotFound)
end
end
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
@@ -1,3 +1,3 @@
class ApplicationMailer < ActionMailer::Base
self.delivery_job = ActionMailer::MailDeliveryJob
self.delivery_job = MailDeliveryJob
end

0 comments on commit 39dab08

Please sign in to comment.