feat: 12小时推送预警轨迹锁添加非阻塞锁
This commit is contained in:
parent
a4f78e7bb6
commit
f4313461a0
@ -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);
|
||||
}
|
||||
}
|
||||
@ -21,44 +21,49 @@ public partial class GlobalConst
|
||||
/// 轨迹拉取配置信息redis key前缀
|
||||
/// </summary>
|
||||
public const string TrackPullContentKeyPrefix = "TrackPullContent";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 预警通知redis key
|
||||
/// </summary>
|
||||
public const string ForewarningNotifyKey = "ForewarningNotify";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 预警通知剩余次数redis key
|
||||
/// </summary>
|
||||
public const string ForewarningNotifyCntKey = "ForewarningNotifyCnt";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// kpi区域redis key前缀
|
||||
/// </summary>
|
||||
public const string KpiAreaKeyPrefix = "KpiArea";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 城市时区redis key前缀
|
||||
/// </summary>
|
||||
public const string CityTimezoneKeyPrefix = "CityTimezone";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 港口时区redis key前缀
|
||||
/// </summary>
|
||||
public const string PortTimezoneKeyPrefix = "PortTimezone";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发布订阅通知频道Key
|
||||
/// </summary>
|
||||
public const string PublishNotifyChannelKey = "PublishNotifyChannel";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹区域reids key
|
||||
/// </summary>
|
||||
public const string TrackAreaKeyPrefix = "TrackArea";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹预警数据redis key前缀
|
||||
/// </summary>
|
||||
public const string TrackWarningKeyPrefix = "TrackWarning";
|
||||
|
||||
/// <summary>
|
||||
/// 12小时推送预警轨迹锁
|
||||
/// </summary>
|
||||
public const string TrackPushTrackWaringLockKey = "TrackPushTrackWaringLock";
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user