Class: DeliveryArrivedAtWarehouseNotificationHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/delivery_arrived_at_warehouse_notification_handler.rb

Overview

Sends the "new delivery arrived at warehouse" notification to the store's
operations email so warehouse dashboards / Slack channels surface the work
item.

WHY async via event: the delivery is captured by id at publish time and
re-queried at perform time, so a destroy between the at_warehouse
transition and the email send (e.g. an order cancellation that cascades
dependent: :destroy on deliveries) is a clean no-op instead of
ActiveJob::DeserializationError (AppSignal #4958). Replaces a
Store#notify_of_new_deliveryInternalMailer.…deliver_later(wait: 1.minute)
call whose 60-second pre-dispatch window made the destroy race especially
easy to hit.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ void

This method returns an undefined value.

Processes a persisted arrival event: re-queries the delivery, returns
silently if it's gone, and otherwise sends the new-delivery notification
to the store's operations email list (skipping when the store has none
configured, matching the original Store#notify_of_new_delivery guard).

Parameters:

  • event (RubyEventStore::Event)

    the persisted Events::DeliveryArrivedAtWarehouse event

Raises:

  • (StandardError)

    if sending the notification fails



31
32
33
34
35
36
37
38
39
40
# File 'app/subscribers/delivery_arrived_at_warehouse_notification_handler.rb', line 31

def perform(event)
  delivery = Delivery.find_by(id: event.data[:delivery_id])
  return unless delivery
  return if delivery.store&.order_notification_emails.blank?

  DeliveryMailer.new_delivery_notification(delivery).deliver_now
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end