fix: 实时持仓服务轮询循环增加等待间隔,修正新流水增量判断基准

- Worker: 风险/预付金计算由连续空转改为30秒一轮(可被取消令牌立即唤醒)
- ClientPosiTask: HasNewFlow 改为与上次计算时间比较(原误传当前时间致增量判断失效),轮询间隔2秒
- 30秒兜底全量重算语义保留不变
This commit is contained in:
hjhan
2026-08-28 15:45:08 +08:00
parent fe38e59a9c
commit 587c0d3fc2
2 changed files with 8 additions and 2 deletions
@@ -40,7 +40,10 @@ namespace RealTimeCalcPositionService
{ {
string calctime = memoryCache.Get<string>("calctime"); string calctime = memoryCache.Get<string>("calctime");
var currentTime = DateTime.Now; var currentTime = DateTime.Now;
bool hasNew= RealtimePnlCalc.HasNewFlow(currentTime); //以上次计算时间为基准判断是否有新流水,避免无变化时空转重算
var hasNew = DateTime.TryParseExact(calctime, "yyyy-MM-dd HH:mm:ss.fff",
System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var lastCalcTime)
&& RealtimePnlCalc.HasNewFlow(lastCalcTime);
if (string.IsNullOrEmpty(calctime)|| hasNew) if (string.IsNullOrEmpty(calctime)|| hasNew)
{ {
memoryCache.Set("calctime", currentTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), TimeSpan.FromSeconds(30)); memoryCache.Set("calctime", currentTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), TimeSpan.FromSeconds(30));
@@ -53,6 +56,7 @@ namespace RealTimeCalcPositionService
_logger.Error(ex, "实时持仓服务异常:" + ex.Message); _logger.Error(ex, "实时持仓服务异常:" + ex.Message);
} }
} }
stoppingToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(2));
} }
} }
public async Task StopAsync(CancellationToken cancellationToken) public async Task StopAsync(CancellationToken cancellationToken)
@@ -47,7 +47,9 @@ namespace RealTimeCalcPositionService
{ {
_logger.Error(ex, "实时预付金计算异常:" + ex.Message); _logger.Error(ex, "实时预付金计算异常:" + ex.Message);
} }
//估值数据盘中不变、交易另有事件触发,无需连续轮询
stoppingToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(30));
} }
} }
public async Task StopAsync(CancellationToken cancellationToken) public async Task StopAsync(CancellationToken cancellationToken)