Class: Delivery::InvoicingHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Delivery::InvoicingHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/delivery/invoicing_handler.rb
Overview
Enqueues DeliveryInvoicingWorker after a delivery ships.
Subscribes to: Events::DeliveryShipped
WHY: Invoice creation is computationally expensive, can fail and needs
to be retryable independently of the tracking email. Delegating to the
existing DeliveryInvoicingWorker preserves its deadlock-retry logic and
the :invoicing queue concurrency limit (1 concurrent job via sidekiq-limit_fetch).
Ordering guarantee: Events::DeliveryShipped is published only AFTER
reset_order_discount completes synchronously in ToShippedHandler, so
invoicing always sees correct discount totals.
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/subscribers/delivery/invoicing_handler.rb', line 19 def perform(event) delivery_id = event.data[:delivery_id] delivery = Delivery.find_by(id: delivery_id) return unless delivery return if delivery.invoiced? DeliveryInvoicingWorker.perform_async(delivery_id) rescue StandardError => e ErrorReporting.error(e) raise end |