Class: Activity::SalesActivityHandler
- Inherits:
-
Object
- Object
- Activity::SalesActivityHandler
- Defined in:
- app/subscribers/activity/sales_activity_handler.rb
Overview
Triggers the customer-level open-sales-activity check after an activity is
created or updated, once the transaction has committed.
Subscribes to: Events::ActivityCreated, Events::ActivityUpdated
The check is gated on:
- The event data flag
skip_check_for_open_sales_activity(virtual attr
captured at callback time — set by callers that batch-create activities). - The activity_type must be a sales_activity.
- The activity's party must have an associated customer.
WHY after-commit: check_for_open_sales_activity queries and potentially
updates the customer record. Running after commit avoids nesting mutations
inside the activity save transaction and makes the check retryable in
isolation if something fails.
Instance Method Summary collapse
Instance Method Details
#call(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/subscribers/activity/sales_activity_handler.rb', line 19 def call(event) return if event.data[:skip_check_for_open_sales_activity] activity = Activity.find_by(id: event.data[:activity_id]) return unless activity return unless activity.activity_type&.sales_activity customer = activity.party&.customer return unless customer Rails.logger.info "Activity #{activity.id} triggered check_for_open_sales_activity, delegating to customer" customer.check_for_open_sales_activity rescue StandardError => e ErrorReporting.error(e, activity_id: event.data[:activity_id]) raise end |