Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry_on does not work with until_executed strategy #75

Open
hovo opened this issue Jun 7, 2024 · 1 comment
Open

retry_on does not work with until_executed strategy #75

hovo opened this issue Jun 7, 2024 · 1 comment

Comments

@hovo
Copy link

hovo commented Jun 7, 2024

I have the following ActiveJob declaration with Sidekiq backend, and noticed that the job is not re-enqueued when an error is raised that has a retry_on declaration. I would have expected the job to retry.

class ExampleJob < ApplicationJob
  unique :until_executed on_conflict: :log
  retry_on ExampleError, wait: :polynomially_longer, attempts: 5
  
 end 
@dewski
Copy link

dewski commented Oct 23, 2024

You can fix this by creating a file at lib/active_job/uniqueness/strategies/until_executed_patch.rb:

# frozen_string_literal: true

require "active_job/uniqueness/strategies/until_executed"

module ActiveJob
  module Uniqueness
    module Strategies
      class UntilExecutedPatch < UntilExecuted
        def before_enqueue
          return if lock(resource: lock_key, ttl: lock_ttl)
          # We're retrying the job, so we don't need to lock again
          return if job.executions > 0

          handle_conflict(resource: lock_key, on_conflict: on_conflict)
          abort_job
        end
      end
    end
  end
end

In config/application.rb add the following to the end of the file:

require_relative "../lib/active_job/uniqueness/strategies/until_executed_patch"

Update your unique call to use the patched strategy:

class ExampleJob < ApplicationJob
  unique :until_executed_patch
end

ivannovosad added a commit to getlago/lago-api that referenced this issue Nov 25, 2024
## Context

`retry_on` does not work with `until_executed` strategy.
veeqo/activejob-uniqueness#75

## Description

This PR updates all the jobs that are affected with this issue - a
combination of `retry_on` and `unique :until_executed`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants