|
@@ -1,36 +1,76 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using Microsoft.Extensions.Hosting;
|
|
|
-
|
|
|
-namespace DataSharing.Application.Services
|
|
|
-{
|
|
|
- public class SendTaskHandler : ISendTaskHandler
|
|
|
- {
|
|
|
- public async Task SendAsync(DsSendTask sendTask, CancellationToken cancellationToken)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public interface ISendTaskHandler
|
|
|
- {
|
|
|
- Task SendAsync(DsSendTask sendTask, CancellationToken cancellationToken);
|
|
|
- }
|
|
|
-
|
|
|
- public class SendTaskService : BackgroundService
|
|
|
- {
|
|
|
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
- {
|
|
|
- var count = 0;
|
|
|
- while (!stoppingToken.IsCancellationRequested)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- await Task.Delay(1000, stoppingToken);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//using System;
|
|
|
+//using System.Collections.Generic;
|
|
|
+//using System.Linq;
|
|
|
+//using System.Text;
|
|
|
+//using System.Threading.Tasks;
|
|
|
+//using Consul;
|
|
|
+//using Microsoft.Extensions.DependencyInjection;
|
|
|
+//using Microsoft.Extensions.Hosting;
|
|
|
+//using Microsoft.Extensions.Logging;
|
|
|
+//using Polly.Registry;
|
|
|
+//using XF.Domain.Dependency;
|
|
|
+//using XF.Domain.Exceptions;
|
|
|
+
|
|
|
+//namespace DataSharing.Application.Services
|
|
|
+//{
|
|
|
+// public class SendTaskHandler : ISendTaskHandler, IScopeDependency
|
|
|
+// {
|
|
|
+// private readonly ILogger<SendTaskHandler> _logger;
|
|
|
+
|
|
|
+// public SendTaskHandler(ILogger<SendTaskHandler> logger)
|
|
|
+// {
|
|
|
+// _logger = logger;
|
|
|
+// }
|
|
|
+
|
|
|
+// public async Task SendAsync(int count, CancellationToken cancellationToken)
|
|
|
+// {
|
|
|
+// _logger.LogInformation($"==>执行send开始, count:{count}");
|
|
|
+// var rd = Random.Shared.Next(1000, 10000);
|
|
|
+// if (rd <= 5000)
|
|
|
+// {
|
|
|
+// throw new UserFriendlyException("执行失败");
|
|
|
+// }
|
|
|
+
|
|
|
+// await Task.Delay(rd, cancellationToken);
|
|
|
+
|
|
|
+// _logger.LogInformation($"执行send结束, count:{count}<==");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// public interface ISendTaskHandler
|
|
|
+// {
|
|
|
+// Task SendAsync(int count, CancellationToken cancellationToken);
|
|
|
+// }
|
|
|
+
|
|
|
+// public class SendTaskService : BackgroundService
|
|
|
+// {
|
|
|
+// private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
+
|
|
|
+// public SendTaskService(IServiceScopeFactory serviceScopeFactory)
|
|
|
+// {
|
|
|
+// _serviceScopeFactory = serviceScopeFactory;
|
|
|
+// }
|
|
|
+
|
|
|
+// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
+// {
|
|
|
+// using var scope = _serviceScopeFactory.CreateScope();
|
|
|
+// var provider = scope.ServiceProvider;
|
|
|
+// var pipelineProvider = provider.GetRequiredService<ResiliencePipelineProvider<string>>();
|
|
|
+// var pipeline = pipelineProvider.GetPipeline(StrategyDefaults.RetryStrategy);
|
|
|
+// var handler = provider.GetRequiredService<ISendTaskHandler>();
|
|
|
+
|
|
|
+// var count = 0;
|
|
|
+// while (!stoppingToken.IsCancellationRequested)
|
|
|
+// {
|
|
|
+// await pipeline.ExecuteAsync(async token =>
|
|
|
+// {
|
|
|
+// Console.WriteLine($"execute count:{count}");
|
|
|
+// await handler.SendAsync(count, token);
|
|
|
+// count++;
|
|
|
+// });
|
|
|
+
|
|
|
+// await Task.Delay(1000, stoppingToken);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|