Class: Inventory::DeliveryInvoicedHandler

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

Overview

Releases inventory commits for a delivery's line items after invoicing.

Subscribes to: Events::DeliveryInvoiced

WHY async: Stock reservation release is not financially critical — the
ledger entries are the authoritative inventory record. Running as an
independent subscriber means a failure here won't roll back the invoice,
and the daily ExpiredInventoryCommitsWorker serves as a safety net.

Replaces the inline call to delivery.uncommit_catalog_items that was
previously embedded inside ItemLedgerEntry.process_invoice.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/subscribers/inventory/delivery_invoiced_handler.rb', line 18

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

  delivery.uncommit_catalog_items
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end