Class: Shipping::ItemPackingRefreshHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Shipping::ItemPackingRefreshHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/shipping/item_packing_refresh_handler.rb
Overview
Refreshes the from_item Packing record for an Item whose shipping
dimensions just changed.
Subscribes to: Events::ItemShippingDimensionsChanged
WHY async: the prior synchronous after_save callback added 5-20 ms to
every Item save by running Shipping::ItemMd5Extractor (Packing.upsert
plus a HABTM item_ids |= write). EDI feeds, bulk supplier imports,
and admin spreadsheet pastes save items in tight loops, so that latency
accumulates. The Packing row is a lookup cache, not transactional data,
so a few seconds of staleness is acceptable.
Skip semantics carry over from the old callback at Item#set_packaged_items_md5_hash:
- run only when no
from_itemPacking exists yet, OR an existing one
is invalid, OR boxes actually changed. The publisher gates on
any_box_changed?; this handler re-checkspackings.from_itemso
re-runs from out-of-order delivery / queue retries are safe.
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/subscribers/shipping/item_packing_refresh_handler.rb', line 28 def perform(event) item = Item.find_by(id: event.data[:item_id]) return unless item return unless item.is_goods? return unless item.box1_defined? Shipping::ItemMd5Extractor.new.process(item) rescue StandardError => e ErrorReporting.error(e) raise end |