From 948c5d01461c535f9fd1ca7d64cefac01b069971 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 24 May 2016 06:50:08 -0400 Subject: [PATCH] Update customer.rb --- app/models/customer.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 70ff6d4..5df2bdb 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -107,16 +107,18 @@ class Customer < ActiveRecord::Base query = "Select Id, DisplayName From Customer" query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last - query << " Order By DisplayName " + #query << " Order By DisplayName " without_callback(:save, :before, :save) do Qbo.get_base(:customer).service.query_in_batches(query, per_page: 100) do |batch| batch.each do |customer| - # Update the customer table - qbo_customer = Customer.find_or_create_by(id: customer.id) - qbo_customer.name = customer.display_name - qbo_customer.id = customer.id - qbo_customer.save + Customer.transaction do + # Update the customer table + qbo_customer = Customer.find_or_create_by(id: customer.id) + qbo_customer.name = customer.display_name + qbo_customer.id = customer.id + qbo_customer.save + end end end end @@ -144,6 +146,7 @@ class Customer < ActiveRecord::Base def pull begin #tries ||= 3 + raise Exception if self.id @details = Qbo.get_base(:customer).find_by_id(self.id) rescue #retry unless (tries -= 1).zero?