Class: AmazonRefreshProductTypeSchemasWorker

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

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

For each catalog, collect unique product_types and use catalog.load_orchestrator to iterate over product_type then call orchestrator.pull_schema(product_type) to pull and refresh schemas for each marketplace/locale



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/workers/amazon_refresh_product_type_schemas_worker.rb', line 10

def perform(options = {})
  options = options.symbolize_keys
  catalog_ids = options[:catalog_ids] || Catalog.amazon_sellers.pluck(:id)
  Catalog.where(id: catalog_ids).each do |catalog|
    orchestrator = catalog.load_orchestrator
    product_types = (catalog.catalog_items.available_for_edi_feeds.pluck('distinct amazon_desired_product_type') + catalog.catalog_items.pluck('distinct amazon_reported_product_type')).compact.uniq.reject{|pt| pt.blank?}.sort_by{|pt| pt}
    product_types.each_with_index do |product_type, i|
      at i, "Pulling Amazon JSON Schema for product_type #{product_type} on catalog #{catalog.name}"
      begin
        res = orchestrator.pull_schema(product_type)
      rescue Exception => e
        logger.error e
        ErrorReporting.error e, product_type: product_type, catalog: catalog.name
        store error_message: "Error pulling Amazon JSON Schema for product_type #{product_type}, error: #{e.message}"
      end
    end
  end
  store redirect_to: options[:redirect_to]
end