Class: DeliveryAutomaticallyReleasedNotificationHandler

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

Overview

Sends the "future-release delivery automatically released to the warehouse"
notification to the customer's primary sales rep (or orders@ as fallback).

WHY async via event: the delivery is captured by id at publish time and
re-queried at perform time, so a destroy between cron-publish and email-send
(e.g. an order cancelled while the cron batch was iterating) is a clean
no-op instead of ActiveJob::DeserializationError (AppSignal #4958).
Replaces a direct InternalMailer.…deliver_later call from
Delivery.release_deliveries_past_release_date.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ void

This method returns an undefined value.

Processes a persisted auto-release event: re-queries the delivery and
silently no-ops when it's gone.

Parameters:

  • event (RubyEventStore::Event)

    the persisted Events::DeliveryAutomaticallyReleased event

Raises:

  • (StandardError)

    if sending the notification fails



26
27
28
29
30
31
32
33
34
# File 'app/subscribers/delivery_automatically_released_notification_handler.rb', line 26

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

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