|
@@ -25,6 +25,10 @@ public class PersonnelSyncTimer {
|
|
|
// fixme: 防止上一轮未完成时下一轮重入 (两轮并发会使 QPS 翻倍)
|
|
// fixme: 防止上一轮未完成时下一轮重入 (两轮并发会使 QPS 翻倍)
|
|
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
|
|
|
|
|
|
|
|
|
+ // fixme: 钉钉整点 QPS 高峰偶发 subcode=90002 限流 → 首次失败后再重试 2 次, 间隔 60s 让钉钉冷却; 仍失败放弃等下一次 cron
|
|
|
|
|
+ private static final int MAX_ATTEMPTS = 3;
|
|
|
|
|
+ private static final long RETRY_DELAY_MS = 60_000L;
|
|
|
|
|
+
|
|
|
/** 工作日 08:00 / 13:00 / 18:00 各一次全量同步(单方法挂 3 条 cron,离散时点无法用单条 cron 表达) */
|
|
/** 工作日 08:00 / 13:00 / 18:00 各一次全量同步(单方法挂 3 条 cron,离散时点无法用单条 cron 表达) */
|
|
|
@Scheduled(cron = "0 0 8 ? * MON-FRI")
|
|
@Scheduled(cron = "0 0 8 ? * MON-FRI")
|
|
|
@Scheduled(cron = "0 0 13 ? * MON-FRI")
|
|
@Scheduled(cron = "0 0 13 ? * MON-FRI")
|
|
@@ -40,10 +44,25 @@ public class PersonnelSyncTimer {
|
|
|
}
|
|
}
|
|
|
log.info("[PersonnelSync] 定时同步任务开始 tag={}", tag);
|
|
log.info("[PersonnelSync] 定时同步任务开始 tag={}", tag);
|
|
|
try {
|
|
try {
|
|
|
- java.util.Map<String, Object> stats = personnelSyncService.fullSync(null);
|
|
|
|
|
- log.info("[PersonnelSync] 定时同步任务完成 tag={} {}", tag, stats);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("[PersonnelSync] 定时同步任务失败 tag={}", tag, e);
|
|
|
|
|
|
|
+ for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ java.util.Map<String, Object> stats = personnelSyncService.fullSync(null);
|
|
|
|
|
+ log.info("[PersonnelSync] 定时同步任务完成 tag={} attempt={}/{} {}", tag, attempt, MAX_ATTEMPTS, stats);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("[PersonnelSync] 定时同步任务失败 tag={} attempt={}/{}", tag, attempt, MAX_ATTEMPTS, e);
|
|
|
|
|
+ if (attempt < MAX_ATTEMPTS) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(RETRY_DELAY_MS);
|
|
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ log.warn("[PersonnelSync] 重试等待被中断,放弃本轮 tag={}", tag);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ log.error("[PersonnelSync] 定时同步任务连续 {} 次失败,放弃本轮等待下一次 cron 触发 tag={}", MAX_ATTEMPTS, tag);
|
|
|
} finally {
|
|
} finally {
|
|
|
running.set(false);
|
|
running.set(false);
|
|
|
}
|
|
}
|