-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40c7fd5
commit d46feee
Showing
10 changed files
with
124 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,27 +114,29 @@ def call(command) | |
end | ||
|
||
class OnCalculateTotalValue | ||
include Infra::Retry | ||
|
||
def initialize(event_store) | ||
@repository = Infra::AggregateRootRepository.new(event_store) | ||
@event_store = event_store | ||
end | ||
|
||
def call(command) | ||
@repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
order.calculate_total_value(PricingCatalog.new(@event_store), time_promotions_discount) | ||
with_retry do | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lukaszreszke
Collaborator
|
||
@repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
order.calculate_total_value(PricingCatalog.new(@event_store), time_promotions_discount) | ||
end | ||
end | ||
rescue RubyEventStore::WrongExpectedEventVersion | ||
retry | ||
end | ||
|
||
|
||
|
||
def calculate_sub_amounts(command) | ||
@repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
order.calculate_sub_amounts(PricingCatalog.new(@event_store), time_promotions_discount) | ||
with_retry do | ||
@repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
order.calculate_sub_amounts(PricingCatalog.new(@event_store), time_promotions_discount) | ||
end | ||
end | ||
rescue RubyEventStore::WrongExpectedEventVersion | ||
retry | ||
end | ||
|
||
private | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Infra | ||
module Retry | ||
def with_retry | ||
yield | ||
rescue RubyEventStore::WrongExpectedEventVersion | ||
yield | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require_relative "test_helper" | ||
|
||
module Infra | ||
class RetryTest < Minitest::Test | ||
cover "Infra::Retry" | ||
|
||
include Infra::Retry | ||
|
||
def test_no_error | ||
result = with_retry { true } | ||
assert result | ||
end | ||
|
||
def test_retries_once | ||
attempts = 0 | ||
with_retry do | ||
attempts += 1 | ||
raise RubyEventStore::WrongExpectedEventVersion if attempts == 1 | ||
end | ||
|
||
assert_equal 2, attempts | ||
end | ||
|
||
def test_fails_after_two_attempts | ||
attempts = 0 | ||
assert_raises RubyEventStore::WrongExpectedEventVersion do | ||
with_retry do | ||
attempts += 1 | ||
raise RubyEventStore::WrongExpectedEventVersion | ||
end | ||
end | ||
|
||
assert_equal 2, attempts | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What is the reason for Calculate total value needing a retry? It seems odd.
Did you manage to reproduce it manually?