Class: AmazonRefreshProductTypeSchemasWorker
- Inherits:
-
Object
- Object
- AmazonRefreshProductTypeSchemasWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/amazon_refresh_product_type_schemas_worker.rb
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
-
#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.
Methods included from Workers::StatusBroadcastable::Overrides
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( = {}) = .symbolize_keys catalog_ids = [: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.}" end end end store redirect_to: [:redirect_to] end |