From 77a6262b6e8dfdbd222f973adca844d49f2369b7 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:20:25 +0200 Subject: [PATCH] Address rails 7.1 deprecations when using Concurrency (#1097) --- README.md | 2 +- lib/good_job/active_job_extensions/concurrency.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 324a178a8..6dbe6acf3 100644 --- a/README.md +++ b/README.md @@ -816,7 +816,7 @@ GoodJob.on_thread_error = -> (exception) { Rails.error.report(exception) } By default, GoodJob relies on ActiveJob's retry functionality. -ActiveJob can be configured to retry an infinite number of times, with an exponential backoff. Using ActiveJob's `retry_on` prevents exceptions from reaching GoodJob: +ActiveJob can be configured to retry an infinite number of times, with a polynomial backoff. Using ActiveJob's `retry_on` prevents exceptions from reaching GoodJob: ```ruby class ApplicationJob < ActiveJob::Base diff --git a/lib/good_job/active_job_extensions/concurrency.rb b/lib/good_job/active_job_extensions/concurrency.rb index a25bb42ed..0bf4342fe 100644 --- a/lib/good_job/active_job_extensions/concurrency.rb +++ b/lib/good_job/active_job_extensions/concurrency.rb @@ -36,10 +36,16 @@ def deserialize(job_data) end end + wait_key = if ActiveJob.gem_version >= Gem::Version.new("7.1.0") + :polynomially_longer + else + :exponentially_longer + end + retry_on( GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError, attempts: Float::INFINITY, - wait: :exponentially_longer + wait: wait_key ) before_perform do |job|