The CommandService is the interface to schedule commands in Sequent. To execute a Command pass it to the CommandService. For instance from a Sinatra controller:

class Users < Sinatra::Base
  post '/create' do
      aggregate_id: Sequent.new_uuid,
      name: params[:name]

By default all Commands passed into the CommandService are executed in a single transaction. When something fails and an Exception is raised and the transaction is rolled back.

Commands are executed in the order in which they are scheduled. For instance if you schedule new Commands in a Workflow running in the foreground it will be added to the queue of Commands. For instance:

# command c1 results in event e1
on c1 do
  apply e1

# workflow: event e1 results in new command c3
on e1 do

# main
execute_commands(c1, c2)

The order in which Commands and Events are “executed” is:

  • c1
  • c2
  • c3
  • e1