Class: Yes::Core::CommandHandling::CommandGroupHandler
- Inherits:
-
Object
- Object
- Yes::Core::CommandHandling::CommandGroupHandler
- Includes:
- OpenTelemetry::Trackable
- Defined in:
- lib/yes/core/command_handling/command_group_handler.rb
Overview
High-level orchestrator for executing a Yes::Core::Commands::CommandGroup.
Mirrors CommandHandler but produces a Yes::Core::Commands::CommandGroupResponse carrying the array of published events. Group-level guards run; sub-command guards are bypassed (the executor publishes each sub-command’s event directly).
Instance Method Summary collapse
-
#call(group_name, payload, guards: true, metadata: nil) ⇒ Yes::Core::Commands::CommandGroupResponse
Executes a command group and updates the aggregate’s read model.
-
#initialize(aggregate) ⇒ CommandGroupHandler
constructor
A new instance of CommandGroupHandler.
Constructor Details
#initialize(aggregate) ⇒ CommandGroupHandler
Returns a new instance of CommandGroupHandler.
22 23 24 25 26 |
# File 'lib/yes/core/command_handling/command_group_handler.rb', line 22 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(group_name, payload, guards: true, metadata: nil) ⇒ Yes::Core::Commands::CommandGroupResponse
Executes a command group and updates the aggregate’s read model.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yes/core/command_handling/command_group_handler.rb', line 35 def call(group_name, payload, guards: true, metadata: nil) prepared = prepare_payload(payload, ) cmd = command_utilities.build_group_command(group_name, prepared) guard_evaluator_class = command_utilities.fetch_guard_evaluator_class_for_group(group_name) ReadModelRecoveryService.check_and_recover_with_retries(read_model, aggregate:) if aggregate.class.read_model_enabled? CommandGroupExecutor.new(aggregate). call(cmd, group_name, guard_evaluator_class, skip_guards: !guards) end |