【发布时间】:2013-08-20 03:18:44
【问题描述】:
我已经为我的 iOS 应用程序设置了一个 Rails API。我们有一个群组拆分功能,允许人们邀请人们加入他们的群组并平均分配整个账单。它目前已实施并且运行良好,但是随着组规模的增长,处理事务的时间确实变慢了(由于它们处于循环中而不是一次全部运行)。
我很好奇是否有其他人处理过类似的事情,或者有任何资源可以为我指出正确的方向。目前,我们正在对每个组成员卡进行搁置,如果所有搁置都成功,我们将捕获它们。我们这样做是为了确保组中没有人卡弹跳,如果我们直接借记卡,如果某人的卡弹跳,我们可能会对退款负责。我们正在使用 Balanced Payments ruby 客户端。
我见过赛璐珞宝石或sidekiq。我通常会做所有的 iOS 工作,但我们一直很难让好的人来做 API,所以我决定试一试这个应用程序,到目前为止一直很好,直到我遇到这个问题。
@booking.group.group_members.each do |group_member|
credit_card = CreditCard.find(group_member.credit_card_id)
customer = Balanced::Account.find(group_member.user.customer_uri)
booking = Booking.create(:venue_id => @venue.id,
:user_id => group_member.user_id,
:group_id => @booking.group_id,
:subtotal => @booking.subtotal / @group_count,
:total => @booking.total / @group_count,
:gratuity_fee => @booking.gratuity / @group_count,
:credit_card_fee => @booking.fees / @group_count,
:credit_card_id => group_member.credit_card_id,
:receipt_id => @booking.id,
)
begin
hold = customer.hold({:amount => ((booking.subtotal + booking.booking_fee + booking.gratuity_fee + booking.credit_card_fee) * 100).to_int,
:on_behalf_of_uri => @merchant_uri,
:appears_on_statement_as => "...",
:source_uri => credit_card.credit_card_uri}
)
rescue Balanced::Error => error
#handle errors
render json: error.description, status: error.status_code
end
end
end
这就是我在每张牌上放置的方式。有没有人对我如何并行而不是按顺序处理所有这些有任何想法。我知道 sidekiq 或赛璐珞可以很容易地处理类似的事情,但我担心在处理付款时是否发生错误,以及如果一次全部处理它们如何处理它们。
【问题讨论】:
标签: ios ruby-on-rails asynchronous parallel-processing balanced-payments