Class: PartyResearch::AutoEnricher
- Inherits:
-
Object
- Object
- PartyResearch::AutoEnricher
- Defined in:
- app/services/party_research/auto_enricher.rb
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) ⇒ Object
Public entry point.
Instance Method Summary collapse
- #enqueue ⇒ Object
-
#initialize(party, force: false) ⇒ AutoEnricher
constructor
A new instance of AutoEnricher.
Constructor Details
#initialize(party, force: false) ⇒ AutoEnricher
Returns a new instance of AutoEnricher.
37 38 39 40 |
# File 'app/services/party_research/auto_enricher.rb', line 37 def initialize(party, force: false) @party = party @force = force end |
Class Method Details
.enqueue(party, force: false) ⇒ Object
Public entry point. Returns the PartyResearchRun that was
enqueued, or nil when skipped (not enrichable / debounced /
already running / nothing configured).
33 34 35 |
# File 'app/services/party_research/auto_enricher.rb', line 33 def self.enqueue(party, force: false) new(party, force: force).enqueue end |
Instance Method Details
#enqueue ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/party_research/auto_enricher.rb', line 42 def enqueue return nil unless @party.enrichable_via_research? return nil if skip_for_existing_run? adapters = adapters_for_auto_run return nil if adapters.empty? 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 |