添加项目文件。
This commit is contained in:
19
common/Tnb.Common.Core/EventBus/RetryEventHandlerExecutor.cs
Normal file
19
common/Tnb.Common.Core/EventBus/RetryEventHandlerExecutor.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using JNPF.EventBus;
|
||||
using JNPF.FriendlyException;
|
||||
|
||||
namespace JNPF.EventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 事件执行器-超时控制、失败重试熔断等等.
|
||||
/// </summary>
|
||||
public class RetryEventHandlerExecutor : IEventHandlerExecutor
|
||||
{
|
||||
public async Task ExecuteAsync(EventHandlerExecutingContext context, Func<EventHandlerExecutingContext, Task> handler)
|
||||
{
|
||||
// 如果执行失败,每隔 1s 重试,最多三次
|
||||
await Retry.InvokeAsync(async () =>
|
||||
{
|
||||
await handler(context);
|
||||
}, 3, 1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user