Class: Shipping::DeliveryPrePackPackingHandler

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

Overview

Records the manual-entry pre-pack signature in the Packing table after
pre-pack estimation completes.

Subscribes to: Events::DeliveryPrePacked (piggyback)

WHY piggyback on DeliveryPrePacked rather than a new event:
Delivery#send_delivery_pre_packed_notification already publishes
DeliveryPrePacked from after_all_transactions_commit (the
AppSignal #4958-safe shape), and the payload we need is identical
({ delivery_id: }). The existing
DeliveryPrePackedNotificationHandler keeps doing its email work;
this handler runs alongside and writes the Packing row with
origin: :from_manual_entry.

WHY async: replaces the synchronous
set_packaged_items_md5_hash(origin: :from_manual_entry) call at the
end of the complete_picked pre-pack branch. The extractor work is
bookkeeping; running it in a Sidekiq tick keeps the warehouse UI
responsive and benefits from the same purge_empty_quoting_deliveries
re-query safety the email handler relies on.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ void

This method returns an undefined value.

Re-queries the delivery and runs Shipping::DeliveryMd5Extractor
with origin: :from_manual_entry, recording the pre-pack signature
so the row outranks later from-delivery refreshes via
Packing#authoritative_over?.

Parameters:

  • event (RubyEventStore::Event)

    the persisted Events::DeliveryPrePacked event

Raises:

  • (StandardError)

    if the extractor raises; reported then re-raised so Sidekiq retries



41
42
43
44
45
46
47
48
49
# File 'app/subscribers/shipping/delivery_pre_pack_packing_handler.rb', line 41

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

  Shipping::DeliveryMd5Extractor.new(origin: :from_manual_entry).process(delivery)
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end