Method: Sequent::Core::CommandService#execute_commands

Defined in:
lib/sequent/core/command_service.rb

#execute_commands(*commands) ⇒ Object

Executes the given commands in a single transactional block as implemented by the transaction_provider

For each Command:

  • Validate command

  • Call Sequent::CommandHandler’s listening to the given Command

  • Store and publish Events

  • Any new Command’s (from e.g. workflows) are queued for processing in the same transaction

At the end the transaction is committed and the AggregateRepository’s Unit of Work is cleared.



32
33
34
35
36
37
38
39
40
41
# File 'lib/sequent/core/command_service.rb', line 32

def execute_commands(*commands)
  commands.each do |command|
    if command.respond_to?(:event_aggregate_id) && CurrentEvent.current
      command.event_aggregate_id = CurrentEvent.current.aggregate_id
      command.event_sequence_number = CurrentEvent.current.sequence_number
    end
  end
  commands.each { |command| command_queue.push(command) }
  process_commands
end