opt:异常友好提示
change:调整redis缓存过期时间
This commit is contained in:
parent
7d583b6734
commit
d12ef6d350
@ -8,8 +8,6 @@ namespace SJZY.Track.Application.CAP;
|
||||
|
||||
public class CapFilter : SubscribeFilter
|
||||
{
|
||||
const string ErrorCode = "Error599";
|
||||
|
||||
/// <summary>
|
||||
/// 执行前
|
||||
/// </summary>
|
||||
@ -33,7 +31,7 @@ public class CapFilter : SubscribeFilter
|
||||
|
||||
if (await RedisHelper.Client.ExistsAsync($"CapExecuteFilter:{hash}"))
|
||||
{
|
||||
throw new BusinessException(ErrorCode, $"检测到重复消费,消费参数:{argumentJsonStr}");
|
||||
throw new BusinessException(GlobalConst.CapNoRetryErrorCode, $"检测到重复消费,消费参数:{argumentJsonStr}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,10 +54,10 @@ public class CapFilter : SubscribeFilter
|
||||
{
|
||||
context.DeliverMessage.Headers.TryGetValue("cap-msg-id", out var messageId);
|
||||
|
||||
if (context.Exception is BusinessException ex && ex.Code == ErrorCode)
|
||||
if (context.Exception is BusinessException ex && ex.Code == GlobalConst.CapNoRetryErrorCode)
|
||||
{
|
||||
context.ExceptionHandled = true; // 幂等不做重试
|
||||
LogHelper.Warn(ex.ToString());
|
||||
context.ExceptionHandled = true;
|
||||
LogHelper.Warn(ex.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -48,6 +48,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
{
|
||||
var pushConfigs = await _trackPushCacheService.GetPushContentConfigsAsync(@event.SubSystemId, @event.CustomId);
|
||||
if (pushConfigs == null || pushConfigs.Count == 0) return;
|
||||
if (pushConfigs.First().ServiceProviderCode.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new BusinessException(GlobalConst.CapNoRetryErrorCode, $"该客户{@event.CustomId}未关联服务商,无法推送");
|
||||
}
|
||||
|
||||
_pushConfigs = pushConfigs;
|
||||
|
||||
var orders = await _orderRepository.GetListAsync(x =>
|
||||
|
||||
@ -157,7 +157,7 @@ public class ForewarningCacheService : IForewarningCacheService, ISingletonDepen
|
||||
return new List<ForewarningRuleCacheEntry>();
|
||||
}
|
||||
|
||||
await RedisHelper.Client.SetAsync(key, warnings);
|
||||
await RedisHelper.Client.SetAsync(key, warnings, TimeSpan.FromHours(24));
|
||||
ruleResult = WriteRules(warnings);
|
||||
_rules.TryAdd(key, ruleResult);
|
||||
return ruleResult;
|
||||
|
||||
@ -37,10 +37,16 @@ public class TrackPullCacheService : ITransientDependency, ITrackPullCacheServic
|
||||
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id)
|
||||
{
|
||||
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(id);
|
||||
if (trackPullConfigDetail == null) return null;
|
||||
if (trackPullConfigDetail == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(id);
|
||||
if (trackPullContentList.Count == 0) return null;
|
||||
if (trackPullContentList.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = new TrackPullParamsWithContentDto
|
||||
{
|
||||
@ -50,8 +56,8 @@ public class TrackPullCacheService : ITransientDependency, ITrackPullCacheServic
|
||||
trackPullContentList)
|
||||
};
|
||||
|
||||
await RedisHelper.Client.SetAsync(
|
||||
TrackPullContentKey(trackPullConfigDetail.SubSystemId, trackPullConfigDetail.ServiceProviderCode), data);
|
||||
var key = TrackPullContentKey(trackPullConfigDetail.SubSystemId, trackPullConfigDetail.ServiceProviderCode);
|
||||
await RedisHelper.Client.SetAsync(key, data, TimeSpan.FromHours(24));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ public class Track2InterfaceRelayHttpMessageHandler : DelegatingHandler, ITransi
|
||||
throw new BusinessException(message: $"请在{nameof(Track2InterfaceRelaySubSystemContext)}中调用接口通");
|
||||
}
|
||||
|
||||
var subSystemCode = Track2InterfaceRelaySubSystemContext.Current.Code;
|
||||
var subSystemCode = Track2InterfaceRelaySubSystemContext.Current.SubSystemCode;
|
||||
var config = _options.GetOrDefault(subSystemCode);
|
||||
if (config == null)
|
||||
{
|
||||
|
||||
@ -4,17 +4,17 @@ public class Track2InterfaceRelaySubSystemContext
|
||||
{
|
||||
private static readonly AsyncLocal<Track2InterfaceRelaySubSystemContext?> LocalContext = new();
|
||||
|
||||
public Track2InterfaceRelaySubSystemContext(string code)
|
||||
public Track2InterfaceRelaySubSystemContext(string subSystemCode)
|
||||
{
|
||||
if (code.IsNullOrWhiteSpace())
|
||||
if (subSystemCode.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new BusinessException(message: "请求接口通,服务商代码不能为空,请检查是否绑定服务商");
|
||||
throw new BusinessException(message: "请求接口通需要子系统上下文,子系统代码不能为空,请检查是否配置");
|
||||
}
|
||||
|
||||
Code = code;
|
||||
SubSystemCode = subSystemCode;
|
||||
}
|
||||
|
||||
public string Code { get; set; }
|
||||
public string SubSystemCode { get; set; }
|
||||
public static Track2InterfaceRelaySubSystemContext? Current => LocalContext.Value;
|
||||
|
||||
public static IDisposable Use(Track2InterfaceRelaySubSystemContext context)
|
||||
|
||||
@ -12,5 +12,7 @@ public partial class GlobalConst
|
||||
|
||||
public const string SuccessCode = "200";
|
||||
|
||||
public const string CapNoRetryErrorCode = "599";
|
||||
|
||||
public static DateTime MaxDateTime = new DateTime(2999, 1, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public class TimezoneQueries : ITimezoneQueries, ISugarRepository, ITransientDep
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
await RedisHelper.Client.SetAsync(key, cityTimezone.Timezone, TimeSpan.FromHours(6));
|
||||
await RedisHelper.Client.SetAsync(key, cityTimezone.Timezone, TimeSpan.FromHours(24));
|
||||
return cityTimezone.Timezone;
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class TimezoneQueries : ITimezoneQueries, ISugarRepository, ITransientDep
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
await RedisHelper.Client.SetAsync(key, portTimezone.Timezone, TimeSpan.FromHours(6));
|
||||
await RedisHelper.Client.SetAsync(key, portTimezone.Timezone, TimeSpan.FromHours(24));
|
||||
return portTimezone.Timezone;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user