Class: Yes::Core::CommandHandling::ReadModelRevisionGuard
- Inherits:
-
Object
- Object
- Yes::Core::CommandHandling::ReadModelRevisionGuard
- Defined in:
- lib/yes/core/command_handling/read_model_revision_guard.rb
Overview
Ensures that read model revisions match expected event revisions Uses ExponentialRetrier for retry logic with exponential backoff This handles eventual consistency between the event store and read model databases
Defined Under Namespace
Classes: ContextualLogger, RevisionAlreadyAppliedError, RevisionMismatchError, TimeoutError
Instance Attribute Summary collapse
-
#expected_revision ⇒ Integer
readonly
Gets the expected revision for this guard.
Class Method Summary collapse
-
.call(read_model, expected_revision, revision_column: :revision) { ... } ⇒ Object
Calls the guard with a read model and expected revision.
Instance Method Summary collapse
-
#call { ... } ⇒ Object
Executes the guard logic with retry mechanism.
-
#current_revision ⇒ Integer
Gets the current revision from the read model using the specified column.
-
#initialize(read_model, expected_revision, revision_column: :revision) ⇒ ReadModelRevisionGuard
constructor
A new instance of ReadModelRevisionGuard.
Constructor Details
#initialize(read_model, expected_revision, revision_column: :revision) ⇒ ReadModelRevisionGuard
Returns a new instance of ReadModelRevisionGuard.
79 80 81 82 83 |
# File 'lib/yes/core/command_handling/read_model_revision_guard.rb', line 79 def initialize(read_model, expected_revision, revision_column: :revision) @read_model = read_model @expected_revision = expected_revision @revision_column = revision_column end |
Instance Attribute Details
#expected_revision ⇒ Integer (readonly)
Gets the expected revision for this guard
88 89 90 |
# File 'lib/yes/core/command_handling/read_model_revision_guard.rb', line 88 def expected_revision @expected_revision end |
Class Method Details
.call(read_model, expected_revision, revision_column: :revision) { ... } ⇒ Object
Calls the guard with a read model and expected revision
71 72 73 |
# File 'lib/yes/core/command_handling/read_model_revision_guard.rb', line 71 def call(read_model, expected_revision, revision_column: :revision, &) new(read_model, expected_revision, revision_column:).call(&) end |
Instance Method Details
#call { ... } ⇒ Object
Executes the guard logic with retry mechanism
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/yes/core/command_handling/read_model_revision_guard.rb', line 104 def call(&) retrier = create_retrier begin retrier.call( condition_check: -> { check_revision_and_return_match_status }, failure_message: , timeout_message: , & ) rescue Yes::Core::Utils::ExponentialRetrier::RetryFailedError => e raise RevisionMismatchError, e. rescue Yes::Core::Utils::ExponentialRetrier::TimeoutError => e raise TimeoutError, e. end end |
#current_revision ⇒ Integer
Gets the current revision from the read model using the specified column
93 94 95 |
# File 'lib/yes/core/command_handling/read_model_revision_guard.rb', line 93 def current_revision read_model.public_send(revision_column) end |