Class: Shipping::DeliveryShippedPackingHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Shipping::DeliveryShippedPackingHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/shipping/delivery_shipped_packing_handler.rb
Overview
Refreshes the from_delivery Packing record after a Delivery is shipped.
Subscribes to: Events::DeliveryShipped (piggyback)
WHY piggyback on DeliveryShipped rather than introducing a new event:
Delivery::Transitions::ToShippedHandler already publishes
DeliveryShipped from after_commit, and the payload we need is the
same ({ delivery_id: }). Adding a dedicated event for the original
before_transition any => :shipped site would publish a second event
on every shipped transition without any new information; piggybacking
keeps the handler wiring consistent with NotificationShippingTrackingHandler
and Delivery::InvoicingHandler.
WHY async: the original call lived inside the before_transition so
an extractor raise would abort the transition. We've kept the
negative-total guard inline in before_transition (which is the
actual abort-on-failure invariant); the Packing.upsert work is
bookkeeping that can run after commit.
Skip semantics carry the original predicates: non-shipping line items
present and not a warehouse pickup. Re-checked here so stale queue
retries on a transitioned-back delivery are a clean no-op.
Instance Method Summary collapse
-
#perform(event) ⇒ void
Re-queries the delivery and runs
Shipping::DeliveryMd5Extractorafter a successful shipped transition, refreshing thefrom_deliveryPacking row asynchronously instead of insidebefore_transition.
Instance Method Details
#perform(event) ⇒ void
This method returns an undefined value.
Re-queries the delivery and runs Shipping::DeliveryMd5Extractor
after a successful shipped transition, refreshing the from_delivery
Packing row asynchronously instead of inside before_transition.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/subscribers/shipping/delivery_shipped_packing_handler.rb', line 41 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? Shipping::DeliveryMd5Extractor.new.process(delivery) rescue StandardError => e ErrorReporting.error(e) raise end |