Skip to content

Commit

Permalink
bug(PayInAdvance) - Add dedicated lock_key_arguments for pay in advan…
Browse files Browse the repository at this point in the history
…ce jobs (#2755)

After adding the `PreciseTotalAmountCents` to Clickhouse, we now have
discrepancies between event json. The one coming from Kafka always has
"0.0" set for precise total amount cents while the ruby one has nil.

This causes 2 duplicate invoice jobs to be enqueued for the same event.
The uniqueness key compared all arguments to the job.

The fix is to limit what is used as lock_key via the
`lock_key_arguments` method.
  • Loading branch information
nudded authored Oct 29, 2024
1 parent b38a159 commit 3321c8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/jobs/fees/create_pay_in_advance_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def perform(charge:, event:, billing_at: nil)
result.raise_if_error!
end

def lock_key_arguments
args = arguments.first
event = Events::CommonFactory.new_instance(source: args[:event])
[args[:charge], event.organization_id, event.external_subscription_id, event.transaction_id]
end

private

def tax_error?(result)
Expand Down
6 changes: 6 additions & 0 deletions app/jobs/invoices/create_pay_in_advance_charge_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def perform(charge:, event:, timestamp:, invoice: nil)
)
end

def lock_key_arguments
args = arguments.first
event = Events::CommonFactory.new_instance(source: args[:event])
[args[:charge], event.organization_id, event.external_subscription_id, event.transaction_id]
end

private

def tax_error?(result)
Expand Down

0 comments on commit 3321c8e

Please sign in to comment.