Class: AmazonCatalogItemListingsDataWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/amazon_catalog_item_listings_data_worker.rb

Overview

Sidekiq worker: amazon catalog item listings data.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(options = {}) ⇒ Object

Pulls Amazon Seller API listings data — catalog info, listing info, and the
buy-box/pricing summary — for every Seller Central catalog, NA and EU.

EU was excluded until 2026-08-02, which left us blind there: no buy-box
status, no featured-merchant flag, and no CompetitivePriceThreshold. So
nothing could tell us a German listing was priced 19% above every sibling
EU marketplace until Amazon deactivated it under the Fair Pricing Policy.

This is the prerequisite for repricing the EU marketplaces: the repricer
acts on Amazon's reported reference, and we cannot act on a reference we
never collect. Read-only — it moves no prices on its own.

Parameters:

  • options (Hash) (defaults to: {})

    job options

Options Hash (options):

  • catalog_ids (Array<Integer>)

    Seller Central catalog IDs to pull (defaults to all Amazon Seller Central catalogs)

  • refresh_if_older_than (Time)

    only refresh listings data older than this

  • redirect_to (String)

    path to redirect to when the job completes



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/workers/amazon_catalog_item_listings_data_worker.rb', line 32

def perform(options = {})
  options[:catalog_ids] = CatalogConstants::AMAZON_SELLER_IDS if options[:catalog_ids].blank?
  options[:refresh_if_older_than] = 1.day.ago

  logger.debug("AmazonCatalogItemListingsDataWorker starting")
  start_time = Time.current

  result = Catalog::PullAmazonCatalogsListingsData.new.process(options) do |status|
    total status[:total]
    at status[:at], status[:message]

    # Log progress every 50 items
    if status[:at] % 50 == 0
      elapsed = Time.current - start_time
      rate = status[:at] / elapsed * 60 # items per minute
      logger.info "Progress: #{status[:at]}/#{status[:total]} items (#{rate.round(1)}/min)"
    end
  end

  elapsed = Time.current - start_time
  logger.info "AmazonCatalogItemListingsDataWorker completed in #{elapsed.round(0)}s: #{result.catalog_items_updated.size} updated, #{result.catalog_items_failed.size} failed"

  store redirect_to: options[:redirect_to]
end