Class: PartyResearchRun
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PartyResearchRun
- Defined in:
- app/models/party_research_run.rb
Overview
One row per "Enrich" click on a Party. Tracks which adapters were
selected, the Sidekiq job running them, and run-level state for UI
progress and cost accounting. Findings produced by adapters live on
PartyResearchFinding and persist independently — a run is just the
container for one batch of findings.
Constant Summary collapse
- STATES =
%w[queued running completed failed].freeze
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Has many collapse
Class Method Summary collapse
-
.most_recent(party) ⇒ Object
Latest run for this party regardless of state — used by the duplicates/lead-qualify tab to surface "your auto-enrichment is ready" to the sales manager.
-
.most_recent_with_adapter(party, adapter) ⇒ Object
Most recent successful run that included the given adapter; nil if the adapter has never been run on this party.
-
.pending ⇒ ActiveRecord::Relation<PartyResearchRun>
A relation of PartyResearchRuns that are pending.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.most_recent(party) ⇒ Object
Latest run for this party regardless of state — used by the
duplicates/lead-qualify tab to surface "your auto-enrichment is
ready" to the sales manager.
29 30 31 |
# File 'app/models/party_research_run.rb', line 29 def self.most_recent(party) where(party: party).order(created_at: :desc).first end |
.most_recent_with_adapter(party, adapter) ⇒ Object
Most recent successful run that included the given adapter; nil if the
adapter has never been run on this party.
19 20 21 22 23 24 |
# File 'app/models/party_research_run.rb', line 19 def self.most_recent_with_adapter(party, adapter) where(party: party, state: 'completed') .where('adapters @> ?', [adapter].to_json) .order(finished_at: :desc) .first end |
.pending ⇒ ActiveRecord::Relation<PartyResearchRun>
A relation of PartyResearchRuns that are pending. Active Record Scope
15 |
# File 'app/models/party_research_run.rb', line 15 scope :pending, -> { where(state: %w[queued running]) } |
Instance Method Details
#adapters_list ⇒ Object
33 34 35 |
# File 'app/models/party_research_run.rb', line 33 def adapters_list Array(adapters).map(&:to_s) end |
#complete! ⇒ Object
41 42 43 |
# File 'app/models/party_research_run.rb', line 41 def complete! update!(state: 'completed', finished_at: Time.current) end |
#fail!(message) ⇒ Object
45 46 47 |
# File 'app/models/party_research_run.rb', line 45 def fail!() update!(state: 'failed', finished_at: Time.current, error_message: .to_s.truncate(2000)) end |
#findings ⇒ ActiveRecord::Relation<PartyResearchFinding>
11 |
# File 'app/models/party_research_run.rb', line 11 has_many :findings, class_name: 'PartyResearchFinding', dependent: :destroy |
#requested_by ⇒ Account
10 |
# File 'app/models/party_research_run.rb', line 10 belongs_to :requested_by, class_name: 'Account', optional: true |
#start! ⇒ Object
37 38 39 |
# File 'app/models/party_research_run.rb', line 37 def start! update!(state: 'running', started_at: Time.current) end |