2018-12-19 19:50:56 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-13 11:49:47 +00:00
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow.Default
|
|
|
|
|
{
|
|
|
|
|
public class FlowCleanupMiddleware : ICleanupMiddleware
|
|
|
|
|
{
|
2017-10-17 11:29:16 +00:00
|
|
|
|
public async Task Handle(IMessageContext context, HandlingResult handlingResult)
|
2017-10-13 11:49:47 +00:00
|
|
|
|
{
|
2018-12-19 19:50:56 +00:00
|
|
|
|
if (!context.Items.TryGetValue(ContextItems.FlowContext, out var flowContextObj))
|
2017-10-13 11:49:47 +00:00
|
|
|
|
return;
|
|
|
|
|
var flowContext = (FlowContext)flowContextObj;
|
|
|
|
|
|
2017-10-17 08:34:07 +00:00
|
|
|
|
if (flowContext?.FlowStateLock != null)
|
2017-10-13 11:49:47 +00:00
|
|
|
|
{
|
2017-10-17 11:29:16 +00:00
|
|
|
|
if (handlingResult.ConsumeResponse == ConsumeResponse.Nack
|
|
|
|
|
|| handlingResult.MessageAction == MessageAction.ErrorLog)
|
2017-10-13 11:49:47 +00:00
|
|
|
|
{
|
|
|
|
|
await flowContext.FlowStateLock.DeleteFlowState();
|
|
|
|
|
}
|
|
|
|
|
flowContext.FlowStateLock.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|