Class: ShipmentsTrackingWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/shipments_tracking_worker.rb

Overview

Sidekiq worker: shipments tracking.

Daily reconciliation cron — covers the gap left by the webhook flow:
shipments where tracking_registered_at IS NULL never subscribed to
ShipEngine's push events (carrier didn't map to a SE code, the
registration call was rejected with BusinessRulesError, or the
tracking number pre-dates the registration worker). For everything
WITH tracking_registered_at set, the webhook + ShipmentEvent
projection keeps the summary columns fresh in real time and re-polling
here would just spend SE quota rewriting the same values the webhook
already wrote.

Instance Method Summary collapse

Instance Method Details

#performObject

Gets and updates shipment tracking status for label-completed package
shipments in the process of being delivered that are NOT covered by
webhook-driven updates.



20
21
22
23
24
25
26
27
# File 'app/workers/shipments_tracking_worker.rb', line 20

def perform
  shipments = Shipment.cartons.label_complete.tracking_status_incomplete.where(tracking_registered_at: nil)
  res = Shipping::PackageShipmentTracking.new.process(shipments)
  logger.info " ** ShipmentsTrackingWorker completed. result shipments_tracking_succeeded.count: #{res.shipments_tracking_succeeded.count},  shipments_tracking_failed.count: #{res.shipments_tracking_failed.count}:, shipments_tracking_failed_msgs: #{res.shipments_tracking_failed_msgs.join(', ')}"
  return unless res.shipments_tracking_failed.any?

  ErrorReporting.warning("ShipmentsTrackingWorker: failed tracking the following shipments IDs: #{res.shipments_tracking_failed.map(&:id).join(', ')}, shipments_tracking_failed_msgs: #{res.shipments_tracking_failed_msgs.join(', ')}")
end