Class: Workarea::Orderbot::FulfillmentImporter

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/orderbot/fulfillment_importer.rb

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/workers/workarea/orderbot/fulfillment_importer.rb', line 7

def perform(options = {})
  return unless Orderbot.api_configured?

  Orderbot::ImportLog.log('fulfillment')  do |last_imported_at|
    from_updated_on = options[:from_updated_on] || last_imported_at

    fulfillment_filters = {
      last_updated_date_min: from_updated_on.iso8601
    }

    fulfillment_response = gateway.get_fulfillments(fulfillment_filters)
    raise 'get fulfillment error' unless  fulfillment_response.success?

    import_fulfillment_records(fulfillment_response.body)

    if fulfillment_response.total_pages.to_i > 1
      count = 2

      while count <= fulfillment_response.total_pages.to_i
        page_filters = fulfillment_filters.merge(page: count)
        response = gateway.get_products(page_filters)

        import_fulfillment_records(response.body)

        count = count + 1
      end
    end
  end
end