Class: NotificationShippingTrackingHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- NotificationShippingTrackingHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/notification_shipping_tracking_handler.rb
Overview
Sends the tracking notification email to the customer after a delivery ships.
Subscribes to: Events::DeliveryShipped
WHY async: Email delivery is a side-effect that must not block the warehouse
operator's workflow or risk rolling back the shipment record on failure.
Running after_commit via the event store also ensures the delivery's
shipped_date and tracking number are fully persisted before the mailer reads them.
Skipped for: warehouse pickups, service-only deliveries, and EDI orders
(same conditions as the former synchronous send_tracking_notification step).
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/subscribers/notification_shipping_tracking_handler.rb', line 18 def perform(event) delivery = Delivery.find_by(id: event.data[:delivery_id]) return unless delivery return if skip_tracking_email?(delivery) delivery.order&.reload&.send_tracking_email rescue StandardError => e ErrorReporting.error(e) raise end |