Class: DeliveryPrePackedNotificationHandler

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

Overview

Sends the pre-packed-completion email to the team after a delivery
finishes pre-pack estimation.

WHY async via event: the delivery is captured by id at publish time and
re-queried at perform time, so a same-transaction destroy
(e.g. Itemizable#purge_empty_quoting_deliveries in set_totals) is a
clean no-op instead of ActiveJob::DeserializationError (AppSignal #4958).
Replaces a direct InternalMailer.…deliver_later call inside the
complete_picked flow that captured a GlobalID a destroy-in-same-tx
could invalidate before commit.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ void

This method returns an undefined value.

Processes a persisted pre-pack completion event: clears the delivery's
suggested_packaging_text and emails the team.

Parameters:

  • event (RubyEventStore::Event)

    the persisted Events::DeliveryPrePacked event

Raises:

  • (StandardError)

    if updating the delivery or sending the notification fails



28
29
30
31
32
33
34
35
36
37
# File 'app/subscribers/delivery_pre_packed_notification_handler.rb', line 28

def perform(event)
  delivery = Delivery.find_by(id: event.data[:delivery_id])
  return unless delivery

  delivery.update_column(:suggested_packaging_text, nil)
  DeliveryMailer.delivery_pre_packed_notification(delivery).deliver_now
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end