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

fix(unique-jobs): Fix on retry in unique jobs #2862

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class CreateCustomerAssociationJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100

Expand Down
2 changes: 0 additions & 2 deletions app/jobs/integrations/aggregator/invoices/crm/create_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class CreateJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on Integrations::Aggregator::BasePayload::Failure, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100
Expand Down
2 changes: 0 additions & 2 deletions app/jobs/integrations/aggregator/invoices/crm/update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class UpdateJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on Integrations::Aggregator::BasePayload::Failure, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class CreateCustomerAssociationJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log
ivannovosad marked this conversation as resolved.
Show resolved Hide resolved

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class CreateJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on Integrations::Aggregator::BasePayload::Failure, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Crm
class UpdateJob < ApplicationJob
queue_as 'integrations'

unique :until_executed, on_conflict: :log

retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 10
retry_on Integrations::Aggregator::BasePayload::Failure, wait: :polynomially_longer, attempts: 10
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 100
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ class Application < Rails::Application
config.active_support.cache_format_version = 7.1
end
end

require_relative "../lib/active_job/uniqueness/strategies/until_executed_patch"
27 changes: 27 additions & 0 deletions lib/active_job/uniqueness/strategies/until_executed_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "active_job/uniqueness/strategies/until_executed"

# https://github.com/veeqo/activejob-uniqueness/issues/75
# retry_on does not work with until_executed strategy

module ActiveJob
module Uniqueness
module Strategies
module UntilExecutedPatch
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

ActiveJob::Uniqueness::Strategies::UntilExecuted.prepend(
ActiveJob::Uniqueness::Strategies::UntilExecutedPatch
)