Skip to content

Commit

Permalink
task to clean up forgotten leads
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Nov 30, 2023
1 parent 22f7ead commit d3352bc
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
namespace :accounts do
desc 'Create leads for faculty verified by SheerID and never sent to Salesforce'
# rake accounts:create_leads_for_instructors_not_sent_to_sf
# To be run to fix users that were not sent to SF during bug from 26Jan22 to xxFeb22 (hotfix release date)
task :create_leads_for_instructors_not_sent_to_sf, [:day] => [:environment] do |t, args|
# get all the instructors that don't have lead or contact ids
users = User.where(salesforce_contact_id: nil, salesforce_lead_id: nil, role: :instructor, state: :activated).or(User.where.not(sheerid_verification_id: nil))
users.each { |user|
Newflow::CreateSalesforceLead.perform_later(user: user)
}
# get all the instructors that don't have lead or contact ids and have a complete profile
users = User.where(salesforce_contact_id: nil, salesforce_lead_id: nil, role: :instructor, is_profile_complete: true)

users.each do |user|
lead = OpenStax::Salesforce::Remote::Lead.select(:id, :verification_status).find_by(accounts_uuid: user.uuid)

if lead.nil?
Newflow::CreateOrUpdateSalesforceLead.call(user: user)
else
# set the lead id, this will update their status in UpdateUserLeadInfo
user.salesforce_lead_id = lead.id
user.save
end
end
end
end

0 comments on commit d3352bc

Please sign in to comment.