Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being more cautious about applying revision logic if the saga does no… #1096

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
if (Saga.VariableType.CanBeCastTo<IRevisioned>())
{
writer.WriteComment($"{Saga.VariableType.FullNameInCode()} implements {typeof(IRevisioned).FullNameInCode()}, so Wolverine will try to update based on the revision as a concurrency protection");
writer.WriteLine($"BLOCK:if ({Saga.Usage} != null)");
writer.WriteLine($"var {ExpectedSagaRevision} = {Saga.Usage}.{nameof(IRevisioned.Version)} + 1;");
writer.FinishBlock();
}

Next?.GenerateCode(method, writer);
Expand Down
11 changes: 9 additions & 2 deletions src/Samples/Middleware/AppWithMiddleware/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static void Handle(
#endregion


public record InvalidAccount(Guid AccountId);

#region sample_AccountLookupMiddleware

// This is *a* way to build middleware in Wolverine by basically just
Expand All @@ -82,7 +84,7 @@ public static class AccountLookupMiddleware
{
// The message *has* to be first in the parameter list
// Before or BeforeAsync tells Wolverine this method should be called before the actual action
public static async Task<(HandlerContinuation, Account?)> LoadAsync(
public static async Task<(HandlerContinuation, Account?, OutgoingMessages)> LoadAsync(
IAccountCommand command,
ILogger logger,

Expand All @@ -91,13 +93,18 @@ public static class AccountLookupMiddleware

CancellationToken cancellation)
{
var messages = new OutgoingMessages();
var account = await session.LoadAsync<Account>(command.AccountId, cancellation);
if (account == null)
{
logger.LogInformation("Unable to find an account for {AccountId}, aborting the requested operation", command.AccountId);

messages.RespondToSender(new InvalidAccount(command.AccountId));
return (HandlerContinuation.Stop, null, messages);
}

return (account == null ? HandlerContinuation.Stop : HandlerContinuation.Continue, account);
// messages would be empty here
return (HandlerContinuation.Continue, account, messages);
}
}

Expand Down
Loading