Class: ListingIssues::Sync
- Inherits:
-
Object
- Object
- ListingIssues::Sync
- Defined in:
- app/services/listing_issues/sync.rb
Overview
Reconciles ListingIssue rows against what each provider currently reports.
For every candidate catalog item: upsert the issues the adapter returns
(keyed on fingerprint within (catalog_item, provider), reopening any that
recurred unless a human resolved them) and auto-resolve open rows the
provider no longer reports — so the open set always mirrors the channel.
Idempotent; safe to run on a schedule.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- AUTO_RESOLUTION_NOTE =
resolution_note stamped on auto-resolved rows. Distinguishes them from
human "mark as fixed" so a manual resolution isn't reopened on recurrence. 'auto: no longer reported by provider'
Class Method Summary collapse
-
.adapters ⇒ Array<ListingIssues::BaseAdapter>
All registered provider adapters.
-
.run(logger: Rails.logger) ⇒ Hash{String=>ListingIssues::Sync::Result}
Run every provider's reconcile.
Instance Method Summary collapse
- #call ⇒ ListingIssues::Sync::Result
-
#initialize(adapter, logger: Rails.logger) ⇒ Sync
constructor
A new instance of Sync.
Constructor Details
#initialize(adapter, logger: Rails.logger) ⇒ Sync
Returns a new instance of Sync.
36 37 38 39 |
# File 'app/services/listing_issues/sync.rb', line 36 def initialize(adapter, logger: Rails.logger) @adapter = adapter @logger = logger end |
Class Method Details
.adapters ⇒ Array<ListingIssues::BaseAdapter>
All registered provider adapters.
23 24 25 |
# File 'app/services/listing_issues/sync.rb', line 23 def self.adapters [AmazonAdapter.new, WalmartAdapter.new] end |
.run(logger: Rails.logger) ⇒ Hash{String=>ListingIssues::Sync::Result}
Run every provider's reconcile.
30 31 32 |
# File 'app/services/listing_issues/sync.rb', line 30 def self.run(logger: Rails.logger) adapters.to_h { |adapter| [adapter.provider, new(adapter, logger:).call] } end |
Instance Method Details
#call ⇒ ListingIssues::Sync::Result
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/listing_issues/sync.rb', line 42 def call created = updated = resolved = items = 0 CatalogItem.where(id: @adapter.candidate_item_ids) .includes(:amazon_catalog_item_flags, :listing_issues) .find_each do |catalog_item| items += 1 c, u, r = reconcile(catalog_item, @adapter.issues_for(catalog_item)) created += c updated += u resolved += r end Result.new(created:, updated:, resolved:, items:).tap do |result| @logger.info "[ListingIssues::Sync] #{@adapter.provider}: #{result.to_h}" end end |