Use serializable transaction for EPP domain:renew

#430
This commit is contained in:
Artur Beljajev 2017-04-15 23:41:01 +03:00
parent 2cfcb6d54c
commit d79ce87fba

View file

@ -105,29 +105,36 @@ class Epp::DomainsController < EppController
balance_ok?('renew', period, period_unit) # loading pricelist balance_ok?('renew', period, period_unit) # loading pricelist
ActiveRecord::Base.transaction do begin
success = @domain.renew( ActiveRecord::Base.transaction(isolation: :serializable) do
params[:parsed_frame].css('curExpDate').text, @domain.reload
period, period_unit
)
if success success = @domain.renew(
unless balance_ok?('renew', period, period_unit) params[:parsed_frame].css('curExpDate').text,
handle_errors period, period_unit
fail ActiveRecord::Rollback )
if success
unless balance_ok?('renew', period, period_unit)
handle_errors
fail ActiveRecord::Rollback
end
current_user.registrar.debit!({
sum: @domain_pricelist.price.amount,
description: "#{I18n.t('renew')} #{@domain.name}",
activity_type: AccountActivity::RENEW,
log_pricelist_id: @domain_pricelist.id
})
render_epp_response '/epp/domains/renew'
else
handle_errors(@domain)
end end
current_user.registrar.debit!({
sum: @domain_pricelist.price.amount,
description: "#{I18n.t('renew')} #{@domain.name}",
activity_type: AccountActivity::RENEW,
log_pricelist_id: @domain_pricelist.id
})
render_epp_response '/epp/domains/renew'
else
handle_errors(@domain)
end end
rescue ActiveRecord::StatementInvalid => e
sleep rand / 100
retry
end end
end end