gudtech / spree_retailops

Spree extension for integration with the RetailOps platform
BSD 3-Clause "New" or "Revised" License
0 stars 10 forks source link

Background processing in CatalogController#catalog_push #4

Open chinshr opened 9 years ago

chinshr commented 9 years ago

The catalog_push is one of the slowest actions. I would like it to add background processing for CatalogController#catalog_push, which should speed things up quite a bit.

I have pull request ready, but since the call is async I would need to use a callback providing import errors to an endpoint on the RetailOps side. Do you think that is feasible?

The job looks like this, and I would need to implement Spree::Api::Ratailops.import_results in this example:

class Spree::Retailops::CatalogJob < ActiveJob::Base
  queue_as :default

  attr_reader :params

  def initialize
    @params = {}
    @diag   = []
    @memo   = {}
    @failed = {}
  end

  def perform(products, params = {})
    @params = params

    products.to_a.each { |pd| upsert_product_and_variants(pd) }

    Spree::Api::Ratailops.import_results(@diag)
  end

  private
    include Spree::Api::Retailops::CatalogHelpers
end

CatalogController would add this line:

...
class CatalogController
  ...
  def catalog_push
    ...
    Spree::Retailops::CatalogJob.perform_later(products, params)
    ...
   end
...
chinshr commented 9 years ago

@sorear Would be great to get your feedback.