Skip to content

Commit

Permalink
save not working in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Nov 30, 2023
1 parent 09dfb0b commit d87f634
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions app/routines/update_user_lead_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def call

leads = OpenStax::Salesforce::Remote::Lead.select(:id, :accounts_uuid, :verification_status).where(accounts_uuid: users.map(&:uuid)).to_a.index_by(&:accounts_uuid)

updated_users = users.map do |user|
users.map do |user|
lead = leads[user.uuid]

begin
unless lead.nil?
user.salesforce_lead_id = lead.id # it might change in SF lead merging

old_fv_status = user.faculty_status
user.faculty_status = case lead.faculty_verified
user.faculty_status = case lead.verification_status
when "confirmed_faculty"
:confirmed_faculty
when "pending_faculty"
Expand All @@ -35,12 +35,12 @@ def call
:no_faculty_info
else
Sentry.capture_message("Unknown faculty_verified field: '#{
lead.faculty_verified}'' on lead #{lead.id}")
lead.verification_status}'' on lead #{lead.id}")
end

if user.faculty_status_changed?
SecurityLog.create!(
user: user,
user: user,
event_type: :salesforce_updated_faculty_status,
event_data: {
user_id: user.id,
Expand All @@ -50,13 +50,9 @@ def call
}
)
end
rescue NoMethodError
Sentry.capture_message("User #{user.id} unable to be synced with lead #{lead.id}")
end
end

updated_users.transaction do
updated_users.each(&:save!)
user.save if user.changed?
end
end

break if users.length < BATCH_SIZE
Expand Down

0 comments on commit d87f634

Please sign in to comment.