Class: SolidusBacktracs::Api::ScheduleShipmentSyncsJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/solidus_backtracs/api/schedule_shipment_syncs_job.rb

Instance Method Summary collapse

Instance Method Details

#performObject



8
9
10
11
12
13
14
15
16
# File 'app/jobs/solidus_backtracs/api/schedule_shipment_syncs_job.rb', line 8

def perform
  shipments = query_shipments

  shipments.find_in_batches(batch_size: SolidusBacktracs.config.api_batch_size) do |batch|
    SyncShipmentsJob.perform_later(batch.to_a)
  end
rescue StandardError => e
  SolidusBacktracs.config.error_handler.call(e, {})
end

#query_shipmentsObject



22
23
24
25
26
27
28
29
30
31
# File 'app/jobs/solidus_backtracs/api/schedule_shipment_syncs_job.rb', line 22

def query_shipments
  shipments = SolidusBacktracs::Shipment::PendingApiSyncQuery.apply(
    ::Spree::Shipment
      .joins(inventory_units: [:variant])
      .where("spree_variants.sku" => SolidusBacktracs.config.shippable_skus)
      .where("spree_shipments.state" => :ready)
      .where(backtracs_synced_at: nil)
      .distinct
  )
end

#shippable_skusObject



18
19
20
# File 'app/jobs/solidus_backtracs/api/schedule_shipment_syncs_job.rb', line 18

def shippable_skus
  SolidusBacktracs.config.shippable_skus.present? ? SolidusBacktracs.config.shippable_skus : Spree::Variant.pluck(:sku)
end