2017-10-13 11:49:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow.Default
|
|
|
|
|
{
|
|
|
|
|
public class FlowCleanupMiddleware : ICleanupMiddleware
|
|
|
|
|
{
|
|
|
|
|
public async Task Handle(IMessageContext context, ConsumeResponse response)
|
|
|
|
|
{
|
|
|
|
|
object flowContextObj;
|
|
|
|
|
if (!context.Items.TryGetValue(ContextItems.FlowContext, out flowContextObj))
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
if (response == ConsumeResponse.Nack)
|
|
|
|
|
{
|
|
|
|
|
await flowContext.FlowStateLock.DeleteFlowState();
|
|
|
|
|
}
|
|
|
|
|
flowContext.FlowStateLock.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|