| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** 云仓上报定时任务 */ |
| | | @Slf4j |
| | |
| | | return; |
| | | } |
| | | long nowMs = System.currentTimeMillis(); |
| | | for (CloudWmsNotifyLog logRecord : pending) { |
| | | List<CloudWmsNotifyLog> ready = pending.stream() |
| | | .filter(logRecord -> shouldProcess(logRecord, nowMs)) |
| | | .collect(Collectors.toList()); |
| | | ready.parallelStream().forEach(this::safeProcessOne); |
| | | } |
| | | |
| | | private void safeProcessOne(CloudWmsNotifyLog logRecord) { |
| | | try { |
| | | Integer maxRetry = logRecord.getMaxRetryCount(); |
| | | Integer intervalSeconds = logRecord.getRetryIntervalSeconds(); |
| | | if (maxRetry == null || intervalSeconds == null) { |
| | | log.warn("云仓上报待办跳过:重试参数缺失,id={},bizRef={},maxRetry={},intervalSeconds={}", |
| | | logRecord.getId(), logRecord.getBizRef(), maxRetry, intervalSeconds); |
| | | continue; |
| | | } |
| | | int effectiveIntervalSeconds = Math.max(0, intervalSeconds); |
| | | // if (logRecord.getRetryCount() != null && logRecord.getRetryCount() >= maxRetry) { |
| | | if (!isInfiniteRetry(maxRetry) |
| | | && logRecord.getRetryCount() != null |
| | | && logRecord.getRetryCount() >= maxRetry) { |
| | | log.info("云仓上报待办跳过:重试次数已达上限,id={},bizRef={},retryCount={},maxRetry={}", |
| | | logRecord.getId(), logRecord.getBizRef(), logRecord.getRetryCount(), maxRetry); |
| | | continue; |
| | | } |
| | | if (logRecord.getLastNotifyTime() != null) { |
| | | long elapsed = (nowMs - logRecord.getLastNotifyTime().getTime()) / 1000; |
| | | if (elapsed < effectiveIntervalSeconds) { |
| | | // log.info("云仓上报待办跳过:未到重试间隔,id={},bizRef={},elapsed={}s,interval={}s", |
| | | // logRecord.getId(), logRecord.getBizRef(), elapsed, effectiveIntervalSeconds); |
| | | continue; |
| | | } |
| | | } |
| | | processOne(logRecord); |
| | | } catch (Exception e) { |
| | | log.warn("云仓上报定时任务处理单条异常,id={},bizRef={}:{}", logRecord.getId(), logRecord.getBizRef(), e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private boolean shouldProcess(CloudWmsNotifyLog logRecord, long nowMs) { |
| | | Integer maxRetry = logRecord.getMaxRetryCount(); |
| | | Integer intervalSeconds = logRecord.getRetryIntervalSeconds(); |
| | | if (maxRetry == null || intervalSeconds == null) { |
| | | log.warn("云仓上报待办跳过:重试参数缺失,id={},bizRef={},maxRetry={},intervalSeconds={}", |
| | | logRecord.getId(), logRecord.getBizRef(), maxRetry, intervalSeconds); |
| | | return false; |
| | | } |
| | | if (!isInfiniteRetry(maxRetry) |
| | | && logRecord.getRetryCount() != null |
| | | && logRecord.getRetryCount() >= maxRetry) { |
| | | log.info("云仓上报待办跳过:重试次数已达上限,id={},bizRef={},retryCount={},maxRetry={}", |
| | | logRecord.getId(), logRecord.getBizRef(), logRecord.getRetryCount(), maxRetry); |
| | | return false; |
| | | } |
| | | int effectiveIntervalSeconds = Math.max(0, intervalSeconds); |
| | | if (logRecord.getLastNotifyTime() != null) { |
| | | long elapsed = (nowMs - logRecord.getLastNotifyTime().getTime()) / 1000; |
| | | if (elapsed < effectiveIntervalSeconds) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private void processOne(CloudWmsNotifyLog logRecord) { |