Class: PartyResearch::CustomerProfileChangedHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/party_research/customer_profile_changed_handler.rb

Overview

Re-runs Lead Enrichment when a live lead crosses the homeowner/non-homeowner
profile boundary. That boundary changes the eligible adapter set, so a normal
debounced run could otherwise retain results from the wrong classification.

Constant Summary collapse

LEAD_STATES =
%w[lead_qualify lead prospect].freeze

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/subscribers/party_research/customer_profile_changed_handler.rb', line 13

def perform(event)
  customer = Customer.find_by(id: event.data[:customer_id])
  return unless customer&.state.in?(LEAD_STATES)

  profile_id_before = event.data[:profile_id_before]
  profile_id_after = event.data[:profile_id_after]
  return if profile_id_before.nil?
  return if homeowner?(profile_id_before) == homeowner?(profile_id_after)

  CurrentScope.without_job_tracking do
    PartyResearch::AutoEnricher.enqueue(customer, force: true)
  end
end