Class: TwoPercent::BulkProcessor
- Inherits:
-
Object
- Object
- TwoPercent::BulkProcessor
- Includes:
- ValidatesUserGroupsPatch
- Defined in:
- lib/two_percent/bulk_processor.rb
Instance Method Summary collapse
- #dispatch ⇒ Object
-
#initialize(operations, correlation_id: nil) ⇒ BulkProcessor
constructor
A new instance of BulkProcessor.
Methods included from ValidatesUserGroupsPatch
Constructor Details
#initialize(operations, correlation_id: nil) ⇒ BulkProcessor
Returns a new instance of BulkProcessor.
7 8 9 10 |
# File 'lib/two_percent/bulk_processor.rb', line 7 def initialize(operations, correlation_id: nil) @operations = operations.map(&:with_indifferent_access) @correlation_id = correlation_id end |
Instance Method Details
#dispatch ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/two_percent/bulk_processor.rb', line 12 def dispatch @operations.each do |operation| resource_type, id = parse_path(operation[:path]) # Persist data to two_percent tables first (wrapped in transaction for bulk integrity) ActiveRecord::Base.transaction do record = persist_bulk_operation(operation[:method], resource_type, id, operation[:data]) # Publish domain events based on operation # Note: DELETE operations don't return a record, but still need to publish events if record || operation[:method] == "DELETE" publish_domain_event(operation[:method], resource_type, record, id) end end end end |