Skip to content

Commit

Permalink
[wip] #904: Better sync error message on lock contention (#905)
Browse files Browse the repository at this point in the history
* Added some readme documentation, and some dev support items for local debugging

* Fix build error

* Fix build error take 2

* Sorbet is fun

* Update spring.rb

More fun with sorbet.

* Update spring.rb

Even more Sorbet fun

* [Prod Issue] Fix for Integrations::Errors::LockTimeout on translations (#902)

* Added a more defined error message when getting lock errors on sync

* A tweak for rubocop

Co-authored-by: Nada Ismail <[email protected]>
Co-authored-by: Brennen Ryder <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2022
1 parent 3dbae69 commit 5752c0b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/stripe-force/translate/translate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ def catch_errors_with_salesforce_context(primary: nil, secondary: nil, &block)
message: "Stripe error occurred: #{e.message} #{e.request_id}"
)

raise
rescue Integrations::Errors::LockTimeout
if @user.feature_enabled?(FeatureFlags::CATCH_ALL_ERRORS)
create_user_failure(
salesforce_object: @secondary_salesforce_object || @origin_salesforce_object,
message: "A lock for a related object was unable to be acquired and will be retried later"
)
end

raise
rescue
if @user.feature_enabled?(FeatureFlags::CATCH_ALL_ERRORS)
Expand Down
35 changes: 35 additions & 0 deletions test/integration/test_order_failures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,39 @@ class Critic::OrderFailureTest < Critic::FunctionalTest
assert_equal(SF_ORDER, sync_records.first[prefixed_stripe_field(SyncRecordFields::PRIMARY_OBJECT_TYPE.serialize)])
assert_equal(SyncRecordResolutionStatuses::ERROR.serialize, sync_records.first[prefixed_stripe_field(SyncRecordFields::RESOLUTION_STATUS.serialize)])
end

it 'it creates an error sync record when the product is locked' do

sf_account_id = create_salesforce_account

sf_product_id, _ = salesforce_recurring_product_with_price
sf_product = @user.sf_client.find(SF_PRODUCT, sf_product_id)

sf_order = create_subscription_order(sf_product_id: sf_product_id, sf_account_id: sf_account_id)

locker = Integrations::Locker.new(@user)

locker.lock_on_user do
locker.lock_salesforce_record(sf_product)

sf_account = @user.sf_client.find(SF_ACCOUNT, sf_account_id)

SalesforceTranslateRecordJob.translate(@user, sf_account)

@user.enable_feature(FeatureFlags::CATCH_ALL_ERRORS)

exception = assert_raises(Integrations::Errors::LockTimeout) do
StripeForce::Translate.perform_inline(@user, sf_order.Id)
end
assert_match("lock user-#{@user.salesforce_account_id}-record-Product2-#{sf_product.Id} not available", exception.message)

# Sync Records
sync_records = get_sync_records_by_primary_id(sf_order.Id)
assert_equal(1, sync_records.length)

assert_equal(SF_ORDER, sync_records.first[prefixed_stripe_field(SyncRecordFields::PRIMARY_OBJECT_TYPE.serialize)])
assert_equal(SyncRecordResolutionStatuses::ERROR.serialize, sync_records.first[prefixed_stripe_field(SyncRecordFields::RESOLUTION_STATUS.serialize)])
assert_equal("A lock for a related object was unable to be acquired and will be retried later", sync_records.first[prefixed_stripe_field(SyncRecordFields::RESOLUTION_MESSAGE.serialize)])
end
end
end

0 comments on commit 5752c0b

Please sign in to comment.