Class: Invoice::CaptureFundsHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Invoice::CaptureFundsHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/invoice/capture_funds_handler.rb
Overview
RailsEventStore async subscriber for Events::InvoiceCreated that
triggers funds capture on newly-approved Invoices. Skips paid /
non-unpaid rows so retries on the same invoice are idempotent.
Instance Method Summary collapse
-
#perform(event) ⇒ void
Looks up the Invoice from the event payload and runs #capture_funds? unless it's already paid.
Instance Method Details
#perform(event) ⇒ void
This method returns an undefined value.
Looks up the Invoice from the event payload and runs
Invoice#capture_funds? unless it's already paid. State-machine
transition failures are demoted to warnings; everything else is
re-raised after reporting so Sidekiq's retry kicks in.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/subscribers/invoice/capture_funds_handler.rb', line 17 def perform(event) invoice = Invoice.find_by(id: event.data[:invoice_id]) return unless invoice return if invoice.paid? return unless invoice.unpaid? invoice.capture_funds? logger.info "Invoice::CaptureFundsHandler finished for invoice #{invoice.id}, state: #{invoice.state}" rescue StateMachines::InvalidTransition => e logger.warn "Invoice #{invoice&.id} state transition failed: #{e.}" ErrorReporting.warning(e, source: :res_handler, invoice_id: event.data[:invoice_id]) rescue StandardError => e ErrorReporting.error(e) raise end |