I'm noticing that when a Sidekiq / Active Job fails due to an error being thrown, any database changes that occurred during the job are rolled back. This seems to be an intentional feature to make jobs idempotent.

My problem is that the method run by the job can send emails to users and it uses database modifications to prevent re-sending emails. If the database change is rolled back, then the email will be resent whenever the job is retried.

Here's roughly what my job looks like:

```
class ProcessPaymentsJob < ApplicationJob
  queue_as :default

  def perform(*args)
    begin
      # This can send emails to users.
      PaymentProcessor.perform
    rescue StandardError => error
      puts 'PaymentsJob failed, ignoring'
      puts error
    end
  end
end

```

The job is scheduled to run periodically using [sidekiq-scheduler](https://github.com/moove-it/sidekiq-scheduler). I'm using rails-api v5.

I've added a `rescue` to try to prevent the job from rolling back the database changes but it still happens.

It occurred to me that maybe this isn't a Sidekiq issue at all but a feature of Rails.

What's the best solution here to prevent spamming the user with emails?