feat: 12小时推送预警轨迹锁添加非阻塞锁

This commit is contained in:
钟喜旺 2024-08-07 10:14:19 +08:00
parent a4f78e7bb6
commit f4313461a0
3 changed files with 26 additions and 12 deletions

View File

@ -1,5 +1,6 @@
using DotNetCore.CAP;
using Microsoft.Extensions.Logging;
using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Consts;
@ -22,6 +23,14 @@ public class PushWarningEventHandler : ITransientDependency, ICapSubscribe
[CapSubscribe(GlobalConst.TrackPushWarning)]
public async Task Handle(PushWarningEvent @event)
{
var hasProcess = await RedisHelper.Client.ExistsAsync(GlobalConst.TrackPushTrackWaringLockKey);
if (hasProcess)
{
return;
}
await RedisHelper.Client.SetAsync(GlobalConst.TrackPushTrackWaringLockKey, 1, TimeSpan.FromHours(3));
int total = 0, pageSize = @event.PageSize, waitTime = 1000;
var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList();
@ -38,6 +47,7 @@ public class PushWarningEventHandler : ITransientDependency, ICapSubscribe
} while (rows != pageSize);
}
await RedisHelper.Client.DelAsync(GlobalConst.TrackPushTrackWaringLockKey);
_logger.LogInformation(message: "本次预警扫描了:{total}个订单", total);
}
}

View File

@ -61,4 +61,9 @@ public partial class GlobalConst
/// 轨迹预警数据redis key前缀
/// </summary>
public const string TrackWarningKeyPrefix = "TrackWarning";
/// <summary>
/// 12小时推送预警轨迹锁
/// </summary>
public const string TrackPushTrackWaringLockKey = "TrackPushTrackWaringLock";
}

View File

@ -94,13 +94,12 @@ AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize
.Select((b, a) => new { Order = b })
.ToPageListAsync(pageindex, pageSize);
var latestPushTimeIds = new LinkedList<int>();
var questionZeroIds = new LinkedList<int>();
var latestPushTimeIds = new List<int>();
var questionZeroIds = new List<int>();
foreach (var item in ordersToUpdate)
{
var order = item.Order;
var questionType = !order.LatestPushTime.HasValue
|| order.LatestPushTime < DateTime.Now.AddHours(-12)
var questionType = !order.LatestPushTime.HasValue || order.LatestPushTime < DateTime.Now.AddHours(-12)
? 2
: 0;
if (order.QuestionType == questionType) continue;