Class: Yes::Core::CommandHandling::CommandHandler
- Inherits:
-
Object
- Object
- Yes::Core::CommandHandling::CommandHandler
- Includes:
- OpenTelemetry::Trackable
- Defined in:
- lib/yes/core/command_handling/command_handler.rb
Overview
Handles the complete command execution flow for aggregates This class orchestrates command preparation, execution, and read model updates
Instance Method Summary collapse
-
#call(command_name, payload, guards: true, metadata: nil) ⇒ Yes::Core::Commands::Response
Executes a command and updates the aggregate state.
-
#initialize(aggregate) ⇒ CommandHandler
constructor
Initializes a new CommandHandler.
Constructor Details
#initialize(aggregate) ⇒ CommandHandler
Initializes a new CommandHandler
19 20 21 22 23 |
# File 'lib/yes/core/command_handling/command_handler.rb', line 19 def initialize(aggregate) @aggregate = aggregate @command_utilities = aggregate.send(:command_utilities) @read_model = aggregate.read_model if aggregate.class.read_model_enabled? end |
Instance Method Details
#call(command_name, payload, guards: true, metadata: nil) ⇒ Yes::Core::Commands::Response
Executes a command and updates the aggregate state
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yes/core/command_handling/command_handler.rb', line 32 def call(command_name, payload, guards: true, metadata: nil) prepared_payload = prepare_payload(command_name, payload, ) cmd = command_utilities.build_command(command_name, prepared_payload) guard_evaluator_class = command_utilities.fetch_guard_evaluator_class(command_name) ReadModelRecoveryService.check_and_recover_with_retries(read_model, aggregate:) if aggregate.class.read_model_enabled? response = CommandExecutor.new(aggregate). call(cmd, command_name, guard_evaluator_class, skip_guards: !guards) ReadModelUpdater.new(aggregate).call(response.event, prepared_payload, command_name) if aggregate.class.read_model_enabled? && response.success? response end |