Class: Shipping::DeliveryLabelCompleteHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Shipping::DeliveryLabelCompleteHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/shipping/delivery_label_complete_handler.rb
Overview
Re-extracts the from_delivery Packing record after labels are purchased
so the row stores per-box packdim_contents.
Subscribes to: Events::DeliveryLabelComplete
WHY a second pass after DeliveryReadyForLabeling: at
picking → pending_ship_labels the shipments exist but have no
shipment_contents yet (especially Amazon Buy Shipping). Once labels are
purchased and contents are assigned, we re-run the extractor so the
Packing's per-box item breakdown is recorded for future orders that
share the same packing signature.
WHY async: same rationale as DeliveryReadyForLabelingHandler — the
extractor runs reads, an Md5 hash, a Packing.upsert, and a HABTM
item_ids |= write. Label purchase is the user-visible transition
and shouldn't wait on bookkeeping.
Skip semantics: handler re-checks the publisher's gating predicates
(line_items.non_shipping.any?, !is_warehouse_pickup?, and at least
one packed-or-measured shipment with contents) so stale queue retries
don't write a Packing row that no longer reflects the delivery state.
Instance Method Summary collapse
-
#perform(event) ⇒ void
Re-queries the delivery and re-runs
Shipping::DeliveryMd5Extractoronceshipment_contentsexist, capturing per-boxpackdim_contentsthat weren't available atpicking → pending_ship_labelstime.
Instance Method Details
#perform(event) ⇒ void
This method returns an undefined value.
Re-queries the delivery and re-runs Shipping::DeliveryMd5Extractor
once shipment_contents exist, capturing per-box packdim_contents
that weren't available at picking → pending_ship_labels time.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/subscribers/shipping/delivery_label_complete_handler.rb', line 39 def perform(event) delivery = Delivery.find_by(id: event.data[:delivery_id]) return unless delivery return if delivery.is_warehouse_pickup? return unless delivery.line_items.non_shipping.any? return unless delivery.shipments.packed_or_measured.any? { |s| s.shipment_contents.any? } Shipping::DeliveryMd5Extractor.new.process(delivery) rescue StandardError => e ErrorReporting.error(e) raise end |