This commit is contained in:
xiaolipro 2024-09-19 11:40:57 +08:00
parent 72e81fb4ea
commit 5ca6fe1b21
5 changed files with 49 additions and 20 deletions

View File

@ -1,5 +1,8 @@
using System.Diagnostics;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.Logger;
using SJZY.Track.Application.Options;
using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.OrderAggregate;
namespace SJZY.Track.Application.BackgroundServices; namespace SJZY.Track.Application.BackgroundServices;
@ -9,25 +12,25 @@ namespace SJZY.Track.Application.BackgroundServices;
/// </summary> /// </summary>
public class OrderPullStatusScanner : BackgroundService public class OrderPullStatusScanner : BackgroundService
{ {
private readonly IOptionsMonitor<TrackAppOptions> _options;
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public OrderPullStatusScanner(IOrderRepository orderRepository) public OrderPullStatusScanner(IOrderRepository orderRepository, IOptionsMonitor<TrackAppOptions> options)
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
_options = options;
} }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
var count = await _orderRepository.UpdatePullStatusBySilenceAsync(); var stopwatch = Stopwatch.StartNew();
if (count > 0) var count1 = await _orderRepository.UpdatePullStatusBySilenceAsync();
{
LogHelper.Info($"{nameof(OrderPullStatusScanner)}本次扫描更新了{count}条订单拉取状态");
}
// real del // real del
count = await _orderRepository.ClearPullStatusAsync(); var count2 = await _orderRepository.ClearPullStatusAsync();
LogHelper.Info($"{nameof(OrderPullStatusScanner)}本次扫描删除了{count}条订单拉取状态"); stopwatch.Stop();
LogHelper.Info(
$"{nameof(OrderPullStatusScanner)}本次扫描更新了{count1}条,删除了{count2}条订单拉取状态,耗时{stopwatch.ElapsedMilliseconds}ms");
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken); await Task.Delay(TimeSpan.FromSeconds(_options.CurrentValue.OrderPullStatusScanInterval), stoppingToken);
} }
} }

View File

@ -1,8 +1,10 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Helpers; using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Options;
using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Enums;
using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.Queries;
@ -10,17 +12,20 @@ using SJZY.Track.Domain.Queries;
namespace SJZY.Track.Application.BackgroundServices; namespace SJZY.Track.Application.BackgroundServices;
/// <summary> /// <summary>
/// 轨迹兜底扫描 /// 轨迹(发生地时区)兜底扫描
/// </summary> /// </summary>
public class TrackButtonUpScanner : BackgroundService public class TrackButtomUpScanner : BackgroundService
{ {
private readonly IOptionsMonitor<TrackAppOptions> _options;
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ITimezoneQueries _timezoneQueries; private readonly ITimezoneQueries _timezoneQueries;
public TrackButtonUpScanner(ITimezoneQueries timezoneQueries, IOrderRepository orderRepository) public TrackButtomUpScanner(ITimezoneQueries timezoneQueries, IOrderRepository orderRepository,
IOptionsMonitor<TrackAppOptions> options)
{ {
_timezoneQueries = timezoneQueries; _timezoneQueries = timezoneQueries;
_orderRepository = orderRepository; _orderRepository = orderRepository;
_options = options;
} }
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)

View File

@ -0,0 +1,19 @@
namespace SJZY.Track.Application.Options;
public class TrackAppOptions
{
/// <summary>
/// 轨迹刷新并发度
/// </summary>
public int TrackRefreshFetchCount { get; set; }
/// <summary>
/// 订单拉取状态扫描间隔(秒)
/// </summary>
public int OrderPullStatusScanInterval { get; set; }
/// <summary>
/// 轨迹兜底扫描间隔(秒)
/// </summary>
public int TrackButtomUpScanInterval { get; set; }
}

View File

@ -12,6 +12,7 @@ using SJZY.Track.Application.BackgroundServices;
using SJZY.Track.Application.CAP; using SJZY.Track.Application.CAP;
using SJZY.Track.Application.Contract; using SJZY.Track.Application.Contract;
using SJZY.Track.Application.Localization; using SJZY.Track.Application.Localization;
using SJZY.Track.Application.Options;
using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.Track.Application.Track2InterfaceRelay;
using SJZY.UserCenter.Contracts; using SJZY.UserCenter.Contracts;
using SJZY.UserCenter.SharedModel; using SJZY.UserCenter.SharedModel;
@ -138,7 +139,7 @@ public class SjzyTrackApplicationModule : AbpModule
new() new()
{ {
Queue = GlobalConst.TrackRefreshSubscribe, Queue = GlobalConst.TrackRefreshSubscribe,
FetchCount = configuration.GetValue<ushort>("RabbitMQ:TrackRefreshFetchCount"), FetchCount = configuration.GetValue<ushort>("TrackApp:TrackRefreshFetchCount"),
FailedRequeue = false, FailedRequeue = false,
Declaration = o => Declaration = o =>
{ {
@ -151,8 +152,9 @@ public class SjzyTrackApplicationModule : AbpModule
}; };
}, typeof(SjzyTrackApplicationModule).Assembly); }, typeof(SjzyTrackApplicationModule).Assembly);
context.Services.Configure<TrackAppOptions>(configuration.GetSection("TrackApp"));
context.Services.AddHostedService<OrderPullStatusScanner>(); context.Services.AddHostedService<OrderPullStatusScanner>();
context.Services.AddHostedService<TrackButtonUpScanner>(); context.Services.AddHostedService<TrackButtomUpScanner>();
} }
public override void PreConfigureServices(ServiceConfigurationContext context) public override void PreConfigureServices(ServiceConfigurationContext context)

View File

@ -169,11 +169,11 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
) )
.Script(s => s .Script(s => s
.Source(@" .Source(@"
ctx._source.TrackPlace = params.trackPlace; ctx._source.trackPlace = params.trackPlace;
ctx._source.TrackTime = params.trackTime; ctx._source.trackTime = params.trackTime;
ctx._source.TrackTimeZone = params.trackTimeZone; ctx._source.trackTimeZone = params.trackTimeZone;
ctx._source.UpdateUser = params.updateUser; ctx._source.updateUser = params.updateUser;
ctx._source.UpdateTime = params.updateTime; ctx._source.updateTime = params.updateTime;
") ")
.Params(p => p .Params(p => p
.Add("trackPlace", track.TrackPlace) .Add("trackPlace", track.TrackPlace)