[openstreetmap/openstreetmap-website] Discard jobs when then encounter a deserialization error (PR #4323)

Andy Allan notifications at github.com
Wed Jan 15 17:02:28 UTC 2025


I'm just coming back to this one, and perhaps there might be a way forward. The [API docs show](https://edgeapi.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-discard_on) that `discard_on` can take a block, which allows us to access both the error and the job. So could we use that to only discard jobs if it is an ActiveJob::DeserializationError, but only when that's wrapping an ActiveRecord::RecordNotFound error (and not e.g. connection errors).

```ruby
class MailDeliveryJob < ActionMailer::MailDeliveryJob
  discard_on ActiveJob::DeserializationError do |job, error|
    unless error.is_a?(ActiveRecord::RecordNotFound)
      job.enqueue wait: 5.minutes
  end
end
```

We'd certainly need some tests to make sure this works properly!

I've also [asked on the rails mailing list](https://discuss.rubyonrails.org/t/is-discard-on-activejob-deserializationerror-a-footgun/88442) in case anyone else can shed some light on this. It feels like it could be something that applies more widely.

@tomhughes before I go any further with working on this, how often are you running into this in production? I can't tell how much effort would be worthwhile here.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4323#issuecomment-2593472246
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4323/c2593472246 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250115/cfc36f1a/attachment.htm>


More information about the rails-dev mailing list