RailsEventStore/cqrs-es-sample-with-res

View on GitHub
rails_application/app/read_models/customers/register_customer.rb

Summary

Maintainability
A
20 mins
Test Coverage
module Customers
  class RegisterCustomer < Infra::EventHandler
    def call(event)
      ApplicationRecord.with_advisory_lock(event.data.fetch(:customer_id)) do
        Customer.find_or_create_by(id: event.data.fetch(:customer_id)).update(name: event.data.fetch(:name))
      end
    end
  end
end