RetryEventHandlerExecutor.cs 495 B

12345678910111213141516
  1. namespace Admin.NET.Core;
  2. /// <summary>
  3. /// 事件执行器-超时控制、失败重试熔断等等
  4. /// </summary>
  5. public class RetryEventHandlerExecutor : IEventHandlerExecutor
  6. {
  7. public async Task ExecuteAsync(EventHandlerExecutingContext context, Func<EventHandlerExecutingContext, Task> handler)
  8. {
  9. // 如果执行失败,每隔 1s 重试,最多三次
  10. await Retry.InvokeAsync(async () =>
  11. {
  12. await handler(context);
  13. }, 3, 1000);
  14. }
  15. }