From 20cfedba002bab94fd46e2bb08d6e2d7553c338d Mon Sep 17 00:00:00 2001 From: Hans Mulder Date: Mon, 20 Jan 2020 16:47:59 +0100 Subject: [PATCH] Fixed: delete flowstate when Exception occurs - parallellrequest --- Tapeti.Flow/ContextItems.cs | 7 +++++++ Tapeti.Flow/Default/FlowBindingMiddleware.cs | 3 +++ Tapeti.Flow/Default/FlowContinuationMiddleware.cs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/Tapeti.Flow/ContextItems.cs b/Tapeti.Flow/ContextItems.cs index 8bebc23..d82ae7d 100644 --- a/Tapeti.Flow/ContextItems.cs +++ b/Tapeti.Flow/ContextItems.cs @@ -9,5 +9,12 @@ /// Key given to the FlowContext object as stored in the message context. /// public const string FlowContext = "Tapeti.Flow.FlowContext"; + + /// + /// Indicates if the current message handler is the last one to be called before a + /// parallel flow is done and the convergeMethod will be called. + /// Temporarily disables storing the flow state. + /// + public const string FlowIsConverging = "Tapeti.Flow.IsConverging"; } } diff --git a/Tapeti.Flow/Default/FlowBindingMiddleware.cs b/Tapeti.Flow/Default/FlowBindingMiddleware.cs index dbade9d..8adc5a5 100644 --- a/Tapeti.Flow/Default/FlowBindingMiddleware.cs +++ b/Tapeti.Flow/Default/FlowBindingMiddleware.cs @@ -83,6 +83,9 @@ namespace Tapeti.Flow.Default private static Task HandleParallelResponse(IControllerMessageContext context) { + if (context.Get(ContextItems.FlowIsConverging, out _)) + return Task.CompletedTask; + var flowHandler = context.Config.DependencyResolver.Resolve(); return flowHandler.Execute(new FlowHandlerContext(context), new DelegateYieldPoint(async flowContext => { diff --git a/Tapeti.Flow/Default/FlowContinuationMiddleware.cs b/Tapeti.Flow/Default/FlowContinuationMiddleware.cs index 79a7883..f43f0af 100644 --- a/Tapeti.Flow/Default/FlowContinuationMiddleware.cs +++ b/Tapeti.Flow/Default/FlowContinuationMiddleware.cs @@ -36,6 +36,10 @@ namespace Tapeti.Flow.Default var converge = flowContext.FlowState.Continuations.Count == 0 && flowContext.ContinuationMetadata.ConvergeMethodName != null; + if (converge) + // Indicate to the FlowBindingMiddleware that the state must not to be stored + context.Store(ContextItems.FlowIsConverging, null); + await next(); if (converge) @@ -57,6 +61,7 @@ namespace Tapeti.Flow.Default if (flowContext?.FlowStateLock != null) { + // TODO do not call when the controller method was filtered, if the same message has two methods if (!flowContext.IsStoredOrDeleted()) // The exception strategy can set the consume result to Success. Instead, check if the yield point // was handled. The flow provider ensures we only end up here in case of an exception.