Skip to content

Commit

Permalink
misc: Add more after_commit to avoid deserialization errors (#2803)
Browse files Browse the repository at this point in the history
## Description

This PR adds more `after_commit` to avoid deserialization errors in
sidekiq related to rolled-back resources.
  • Loading branch information
vincent-pochet authored Nov 12, 2024
1 parent b6ada73 commit f564be8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
28 changes: 15 additions & 13 deletions app/services/invoices/refresh_draft_and_finalize_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ def call
end

result.invoice = invoice.reload
unless invoice.closed?
SendWebhookJob.perform_later('invoice.created', invoice)
GeneratePdfAndNotifyJob.perform_later(invoice:, email: should_deliver_email?)
Integrations::Aggregator::Invoices::CreateJob.perform_later(invoice:) if invoice.should_sync_invoice?
Integrations::Aggregator::Invoices::Crm::CreateJob.perform_later(invoice:) if invoice.should_sync_crm_invoice?
Integrations::Aggregator::SalesOrders::CreateJob.perform_later(invoice:) if invoice.should_sync_sales_order?
Invoices::Payments::CreateService.new(invoice).call
Utils::SegmentTrack.invoice_created(invoice)
end
after_commit do
unless invoice.closed?
SendWebhookJob.perform_later('invoice.created', invoice)
GeneratePdfAndNotifyJob.perform_later(invoice:, email: should_deliver_email?)
Integrations::Aggregator::Invoices::CreateJob.perform_later(invoice:) if invoice.should_sync_invoice?
Integrations::Aggregator::Invoices::Crm::CreateJob.perform_later(invoice:) if invoice.should_sync_crm_invoice?
Integrations::Aggregator::SalesOrders::CreateJob.perform_later(invoice:) if invoice.should_sync_sales_order?
Invoices::Payments::CreateService.new(invoice).call
Utils::SegmentTrack.invoice_created(invoice)
end

invoice.credit_notes.each do |credit_note|
track_credit_note_created(credit_note)
SendWebhookJob.perform_later('credit_note.created', credit_note)
CreditNotes::GeneratePdfJob.perform_later(credit_note)
invoice.credit_notes.each do |credit_note|
track_credit_note_created(credit_note)
SendWebhookJob.perform_later('credit_note.created', credit_note)
CreditNotes::GeneratePdfJob.perform_later(credit_note)
end
end

result
Expand Down
10 changes: 6 additions & 4 deletions app/services/wallets/balance/update_ongoing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ def call
update_params = compute_update_params
wallet.update!(update_params)

if update_params[:depleted_ongoing_balance] == true
SendWebhookJob.perform_later('wallet.depleted_ongoing_balance', wallet)
end
after_commit do
if update_params[:depleted_ongoing_balance] == true
SendWebhookJob.perform_later('wallet.depleted_ongoing_balance', wallet)
end

::Wallets::ThresholdTopUpService.call(wallet:)
::Wallets::ThresholdTopUpService.call(wallet:)
end

result.wallet = wallet
result
Expand Down

0 comments on commit f564be8

Please sign in to comment.