diff --git a/Admin.NET/Admin.NET.Application/Service/Test/TestService.cs b/Admin.NET/Admin.NET.Application/Service/Test/TestService.cs index 6321f132..1b546135 100644 --- a/Admin.NET/Admin.NET.Application/Service/Test/TestService.cs +++ b/Admin.NET/Admin.NET.Application/Service/Test/TestService.cs @@ -37,7 +37,7 @@ public class TestService : IDynamicApiController /// Redis事件测试 - Payload 🔖 /// /// - public async void EventTestAsync() + public async Task EventTestAsync() { await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, "Admin.NET"); } diff --git a/Admin.NET/Admin.NET.Core/EventBus/RedisEventSourceStorer.cs b/Admin.NET/Admin.NET.Core/EventBus/RedisEventSourceStorer.cs index 0ad569c3..511abe13 100644 --- a/Admin.NET/Admin.NET.Core/EventBus/RedisEventSourceStorer.cs +++ b/Admin.NET/Admin.NET.Core/EventBus/RedisEventSourceStorer.cs @@ -57,8 +57,8 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable FullRedis redis = (FullRedis)cacheProvider.Cache; var clusterOpt = App.GetConfig("Cluster", true); _queueBroadcast = redis.GetStream(routeKey + ":broadcast"); - _queueBroadcast.Group = clusterOpt.ServerId;//根据服务器标识分配到不同的分组里 - _queueBroadcast.Expire = TimeSpan.FromSeconds(10);//消息10秒过期() + _queueBroadcast.Group = clusterOpt.ServerId; //根据服务器标识分配到不同的分组里 + _queueBroadcast.Expire = TimeSpan.FromSeconds(10); //消息10秒过期() _queueBroadcast.ConsumeAsync(OnConsumeBroadcast); // 创建队列消息订阅者,只要有一个服务节点消费了消息即可 @@ -98,6 +98,7 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable Console.WriteLine($"有消息要处理{ces.EventId},{ces.Payload}"); Console.ForegroundColor = oriColor; } + await _channel.Writer.WriteAsync(ces, cancel); } @@ -151,9 +152,9 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable /// /// 释放非托管资源 /// - public async void Dispose() + public void Dispose() { - await _eventConsumer.Stop(); + _eventConsumer.Stop().GetAwaiter().GetResult(); GC.SuppressFinalize(this); } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs index ec65b5e6..4207d42a 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -344,7 +344,7 @@ public class SysAuthService : IDynamicApiController, ITransient /// 退出系统 🔖 /// [DisplayName("退出系统")] - public async void Logout() + public async Task Logout() { var httpContext = _httpContextAccessor.HttpContext ?? throw Oops.Oh(ErrorCodeEnum.D1016); diff --git a/Admin.NET/Admin.NET.Core/Service/Job/JobClusterServer.cs b/Admin.NET/Admin.NET.Core/Service/Job/JobClusterServer.cs index 59a6ddd7..2a88db5c 100644 --- a/Admin.NET/Admin.NET.Core/Service/Job/JobClusterServer.cs +++ b/Admin.NET/Admin.NET.Core/Service/Job/JobClusterServer.cs @@ -23,19 +23,19 @@ public class JobClusterServer : IJobClusterServer /// 当前作业调度器启动通知 /// /// 作业集群服务上下文 - public async void Start(JobClusterContext context) + public void Start(JobClusterContext context) { using var scope = _serviceScopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService().CopyNew(); // 在作业集群表中,如果 clusterId 不存在,则新增一条(否则更新一条),并设置 status 为 ClusterStatus.Waiting - if (await db.Queryable().AnyAsync(u => u.ClusterId == context.ClusterId)) + if (db.Queryable().Any(u => u.ClusterId == context.ClusterId)) { - await db.Updateable().SetColumns(u => u.Status == ClusterStatus.Waiting).Where(u => u.ClusterId == context.ClusterId).ExecuteCommandAsync(); + db.Updateable().SetColumns(u => u.Status == ClusterStatus.Waiting).Where(u => u.ClusterId == context.ClusterId).ExecuteCommand(); } else { - await db.Insertable(new SysJobCluster { ClusterId = context.ClusterId, Status = ClusterStatus.Waiting }).ExecuteCommandAsync(); + db.Insertable(new SysJobCluster { ClusterId = context.ClusterId, Status = ClusterStatus.Waiting }).ExecuteCommand(); } } @@ -72,7 +72,9 @@ public class JobClusterServer : IJobClusterServer return; } } - catch { } + catch + { + } } } @@ -80,24 +82,24 @@ public class JobClusterServer : IJobClusterServer /// 当前作业调度器停止通知 /// /// 作业集群服务上下文 - public async void Stop(JobClusterContext context) + public void Stop(JobClusterContext context) { // 在作业集群表中,更新 clusterId 的 status 为 ClusterStatus.Crashed using var scope = _serviceScopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService().CopyNew(); - await db.Updateable(new SysJobCluster { Status = ClusterStatus.Crashed }).Where(u => u.ClusterId == context.ClusterId).ExecuteCommandAsync(); + db.Updateable(new SysJobCluster { Status = ClusterStatus.Crashed }).Where(u => u.ClusterId == context.ClusterId).ExecuteCommand(); } /// /// 当前作业调度器宕机 /// /// 作业集群服务上下文 - public async void Crash(JobClusterContext context) + public void Crash(JobClusterContext context) { // 在作业集群表中,更新 clusterId 的 status 为 ClusterStatus.Crashed using var scope = _serviceScopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService().CopyNew(); - await db.Updateable(new SysJobCluster { Status = ClusterStatus.Crashed }).Where(u => u.ClusterId == context.ClusterId).ExecuteCommandAsync(); + db.Updateable(new SysJobCluster { Status = ClusterStatus.Crashed }).Where(u => u.ClusterId == context.ClusterId).ExecuteCommand(); } ///