diff --git a/lib/tasks/accounts/update_adopter_status.rake b/lib/tasks/accounts/update_adopter_status.rake index 811891834..e1f1e5ac3 100644 --- a/lib/tasks/accounts/update_adopter_status.rake +++ b/lib/tasks/accounts/update_adopter_status.rake @@ -5,26 +5,24 @@ namespace :accounts do loop do users = User.where(adopter_status: nil).where.not(salesforce_contact_id: nil ).limit(250) - begin - contacts = OpenStax::Salesforce::Remote::Contact.select( - :id, - :adoption_status, - :accounts_uuid - ) - .where(id: users.map(&:salesforce_contact_id)) - .index_by(&:id) + contacts = OpenStax::Salesforce::Remote::Contact.select( + :id, + :adoption_status, + :accounts_uuid + ) + .where(id: users.map(&:salesforce_contact_id)) + .index_by(&:id) - updated_users = users.map do |user| - contact = contacts[user.salesforce_contact_id] - user.adopter_status = contact.adoption_status - end + updated_users = users.map do |user| + contact = contacts[user.salesforce_contact_id] + user.adopter_status = contact.adoption_status + end - updated_users.transaction do - updated_users.each(&:save!) - end - rescue StandardError => se - Sentry.capture_exception se + updated_users.transaction do + updated_users.each(&:save!) end + + break if users.length < 250 end end end