Class: ContactPointPhoneChangedHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- ContactPointPhoneChangedHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/contact_point_phone_changed_handler.rb
Overview
Handles Events::ContactPointPhoneChanged: backfills origin_party_id and
destination_party_id on CallRecord rows whose number matches the new phone
detail but had no party association yet.
Moved from ContactPoint#associate_call_records (after_save, inside transaction)
to after_commit so the backfill runs outside the save transaction and only
when the record is definitely persisted.
Runs asynchronously via ActiveJob so the CallRecord update_all queries do not
block the request cycle.
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/subscribers/contact_point_phone_changed_handler.rb', line 17 def perform(event) party_id = event.data[:party_id] number = event.data[:detail].to_s CallRecord.where(origin_number: number).where(origin_party_id: nil).update_all(origin_party_id: party_id) CallRecord.where(destination_number: number).where(destination_party_id: nil).update_all(destination_party_id: party_id) end |