From 4f5f8b4cfa2bad160df363326b6daa31f9f67f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=BE=99=20=E7=8E=8B?= Date: Mon, 21 Oct 2024 09:12:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20=5F=3DTask.Run(?= =?UTF-8?q?)=20=E4=BD=BF=E7=94=A8abp=E7=9A=84ApplicationService=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84LazyServiceProvider=E5=88=9B=E5=BB=BAscope?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E5=B5=8C=E5=A5=97scope=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=BC=82=E5=B8=B8=20=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=96=B9=E6=B3=95=EF=BC=9A=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?IServiceScopeFactory=E5=88=9B=E5=BB=BAscope=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TimerTaskss/TrackPullTask.cs | 9 ++++++++- .../Services/TimerTaskss/TrackPushTask.cs | 9 ++++++++- .../Services/TimerTaskss/TrackWarningTask.cs | 7 +++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs index 460bd655..6bd0edb1 100644 --- a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs +++ b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs @@ -22,6 +22,13 @@ namespace SJZY.Track.Application.Services.TimerTaskss; [ApiExplorerSettings(GroupName = "定时任务")] public class TrackPullTask : ApplicationService, ISingletonDependency { + private readonly IServiceScopeFactory _serviceScopeFactory; + + public TrackPullTask(IServiceScopeFactory serviceScopeFactory) + { + _serviceScopeFactory = serviceScopeFactory; + } + /// /// 定时任务刷新轨迹 /// @@ -30,7 +37,7 @@ public class TrackPullTask : ApplicationService, ISingletonDependency [HttpPost("/TimerTask/Refresh")] public async Task RefreshForTaskAsync() { - using var serviceScope = LazyServiceProvider.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var provideQueries = serviceScope.ServiceProvider.GetRequiredService(); var configs = await provideQueries.GetAllPullConfigsAsync(); diff --git a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPushTask.cs b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPushTask.cs index 928b54e9..47f150de 100644 --- a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPushTask.cs +++ b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPushTask.cs @@ -13,6 +13,13 @@ namespace SJZY.Track.Application.Services.TimerTaskss; [ApiExplorerSettings(GroupName = "定时任务")] public class TrackPushTask : ApplicationService { + private readonly IServiceScopeFactory _serviceScopeFactory; + + public TrackPushTask(IServiceScopeFactory serviceScopeFactory) + { + _serviceScopeFactory = serviceScopeFactory; + } + /// /// 定时任务推送预警(》12小时没有推送的) /// @@ -21,7 +28,7 @@ public class TrackPushTask : ApplicationService [HttpPost("/TimerTask/PushWarn")] public async Task PushWarnForTaskAsync() { - using var serviceScope = LazyServiceProvider.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var configs = serviceScope.ServiceProvider.GetRequiredService>() .Value; diff --git a/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs b/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs index 655f2995..7696262d 100644 --- a/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs +++ b/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs @@ -16,11 +16,14 @@ public class TrackWarningTask : ApplicationService { private readonly IOptionsSnapshot _options; private readonly IOrderRepository _orderRepository; + private readonly IServiceScopeFactory _serviceScopeFactory; - public TrackWarningTask(IOrderRepository orderRepository, IOptionsSnapshot options) + public TrackWarningTask(IOrderRepository orderRepository, IOptionsSnapshot options, + IServiceScopeFactory serviceScopeFactory) { _orderRepository = orderRepository; _options = options; + _serviceScopeFactory = serviceScopeFactory; } /// @@ -63,7 +66,7 @@ public class TrackWarningTask : ApplicationService { try { - using var serviceScope = LazyServiceProvider.CreateScope(); + using var serviceScope = _serviceScopeFactory.CreateScope(); var forewarningNotifyService = serviceScope.ServiceProvider.GetRequiredService(); From c9a2e8d824c81ddb28254e23504138dabaee7ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=BE=99=20=E7=8E=8B?= Date: Tue, 22 Oct 2024 14:34:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=A3=B0=E6=98=8E=E4=B8=BA?= =?UTF-8?q?=E5=8D=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TimerTaskss/TrackWarningTask.cs | 3 ++- .../Services/TrackPush/TrackPushService.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs b/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs index 7696262d..3b9a93d3 100644 --- a/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs +++ b/src/SJZY.Track.Application/Services/TimerTaskss/TrackWarningTask.cs @@ -5,6 +5,7 @@ using SJZY.Expand.ABP.Core.Logger; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.Track.Domain.Aggregates.OrderAggregate; +using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TimerTaskss; @@ -12,7 +13,7 @@ namespace SJZY.Track.Application.Services.TimerTaskss; /// 轨迹运输时效预警定时任务 /// [ApiExplorerSettings(GroupName = "定时任务")] -public class TrackWarningTask : ApplicationService +public class TrackWarningTask : ApplicationService, ISingletonDependency { private readonly IOptionsSnapshot _options; private readonly IOrderRepository _orderRepository; diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index 93a5e4c7..66e95cf2 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -8,6 +8,7 @@ using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPush; +using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackPush; @@ -16,7 +17,7 @@ namespace SJZY.Track.Application.Services.TrackPush; /// [ApiExplorerSettings(GroupName = "轨迹推送")] [Route("/Track/PushConfig")] -public class TrackPushService : ApplicationService +public class TrackPushService : ApplicationService, ISingletonDependency { private readonly IStringLocalizer _stringLocalizer; private readonly ITrackPushCacheService _trackPushCacheService;