Module: Sequent::Util::DryRun

Defined in:
lib/sequent/util/dry_run.rb

Overview

Dry run provides the ability to inspect what would happen if the given commands would be executed without actually committing the results. You can inspect which commands are executed and what the resulting events would be with theSequent::Projector’s and Sequent::Workflow’s that would be invoked (without actually invoking them).

Since the Workflow’s are not actually invoked new commands resulting from this Workflow will of course not be in the result.

Caution: Since the Sequent Configuration is shared between threads this method is not Thread safe.

Example usage:

result = Sequent.dry_run(create_foo_command, ping_foo_command)

result.print(STDOUT)

Defined Under Namespace

Classes: EventInvokedHandler, EventStoreProxy, RecordingEventPublisher, Result

Class Method Summary collapse

Class Method Details

.these_commands(commands) ⇒ Object

Main method of the DryRun.

Caution: Since the Sequent Configuration is changed and is shared between threads this method is not Thread safe.

After invocation the sequent configuration is reset to the state it was before invoking this method.

Parameters:

  • commands
    • the commands to dry run

Returns:

  • Result - the Result of the dry run. See Result.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/sequent/util/dry_run.rb', line 177

def self.these_commands(commands)
  current_event_store = Sequent.configuration.event_store
  current_event_publisher = Sequent.configuration.event_publisher
  current_transaction_provider = Sequent.configuration.transaction_provider

  result = Result.new

  Sequent.configuration.event_store = EventStoreProxy.new(result, current_event_store)
  Sequent.configuration.event_publisher = RecordingEventPublisher.new(result)
  Sequent.configuration.transaction_provider =
    Sequent::Core::Transactions::ReadOnlyActiveRecordTransactionProvider.new(current_transaction_provider)

  Sequent.command_service.execute_commands(*commands)

  result
ensure
  Sequent.configuration.event_store = current_event_store
  Sequent.configuration.event_publisher = current_event_publisher
  Sequent.configuration.transaction_provider = current_transaction_provider
end