Class: PartyResearch::AutoEnricher
- Inherits:
-
Object
- Object
- PartyResearch::AutoEnricher
- Defined in:
- app/services/party_research/auto_enricher.rb
Overview
Automatic Lead Enrichment trigger fired by the Customer state machine
when a record transitions into lead_qualify. Drops a fresh
PartyResearchRun onto Sidekiq with every configured + relevant
adapter so the sales manager sees curated findings already waiting
on the duplicates tab the next morning.
Idempotent at the day-grain level — won't re-run if an enrichment
kicked off in the last DEBOUNCE window. Sidekiq retry safety lives
in the Orchestrator (per-adapter resume guard).
Constant Summary collapse
- DEBOUNCE =
6.hours
- SETTLE_DELAY =
Wait this long before the worker runs so writes that follow lead
creation in the same session — name cleanup, profile
classification, contact attachment — commit first. Enriching the
instant a guest hitslead_qualifyran against a still-raw record
(placeholder name, default Homeowner profile, no Contact) and
wasted the run. 10.minutes
Class Method Summary collapse
-
.enqueue(party, force: false, only: nil) ⇒ Object
Public entry point.
Instance Method Summary collapse
- #enqueue ⇒ Object
-
#initialize(party, force: false, only: nil) ⇒ AutoEnricher
constructor
A new instance of AutoEnricher.
Constructor Details
#initialize(party, force: false, only: nil) ⇒ AutoEnricher
Returns a new instance of AutoEnricher.
41 42 43 44 45 |
# File 'app/services/party_research/auto_enricher.rb', line 41 def initialize(party, force: false, only: nil) @party = party @force = force @only = only&.map(&:to_s).presence end |
Class Method Details
.enqueue(party, force: false, only: nil) ⇒ Object
Public entry point. Returns the PartyResearchRun that was
enqueued, or nil when skipped (not enrichable / debounced /
already running / nothing configured).
37 38 39 |
# File 'app/services/party_research/auto_enricher.rb', line 37 def self.enqueue(party, force: false, only: nil) new(party, force: force, only: only).enqueue end |
Instance Method Details
#enqueue ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/party_research/auto_enricher.rb', line 47 def enqueue return nil unless @party.enrichable_via_research? adapters = adapters_for_auto_run return nil if adapters.empty? return nil if skip_for_existing_run?(adapters) run = PartyResearchRun.create!(party: @party, adapters: adapters) jid = PartyEnrichmentWorker.perform_in(SETTLE_DELAY, run.id) run.update!(sidekiq_jid: jid) run rescue StandardError => e # Auto-enrichment is best-effort — never block the state # transition (or whatever else triggered it) on a queueing # hiccup. Rails.logger.warn("[PartyResearch::AutoEnricher] #{@party.class.name}##{@party.id} failed: #{e.class}: #{e.}") nil end |