fix: 供应商账号拉取启动期大批失败 (启动推迟 30s + 同步切 100/批)

- @PostConstruct init() 加 Thread.sleep(30s), 避开启动期 Druid 首批物理连接未就绪导致全量失败
- sync() 改 100 条/批 + 批间 Thread.sleep(100ms), 让连接池稳定归还, 避免大批并发撑爆 Druid

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
郭庆泰
2026-09-16 00:45:46 +08:00
co-authored by Claude Code
parent 0fb98311ce
commit e8aed39675
@@ -68,13 +68,15 @@ public class SupplierAccountPullScheduler
return t;
});
/** 启动后立即全量拉取 1 个月数据 (异步, 不阻塞 Spring 启动) */
/** 启动后推迟 30s 全量拉取 1 个月数据 (异步, 不阻塞 Spring 启动; 推迟避开启动期 Druid 池首批连接未就绪) */
@PostConstruct
public void init()
{
startupExecutor.submit(() -> {
try
{
// 启动期 Druid 首批物理连接未建好, 推迟 30s 让连接池就绪, 避免大批失败
Thread.sleep(30_000);
log.info("[SupplierAccountPull] 启动全量拉取开始 (近 {} 天)", fullPullDays());
pull(fullPullDays() * 24 * 60);
}
@@ -142,11 +144,21 @@ public class SupplierAccountPullScheduler
fetched += size;
// 同步到执行方 sys_user / biz_org / biz_person (按邮箱 upsert)
// 切批 100 条/批, 批间 sleep 100ms 让连接池归还, 避免大批并发撑爆 Druid
if (size > 0)
{
List<SupplierAccount> accounts =
objectMapper.convertValue(rows, new TypeReference<List<SupplierAccount>>() {});
supplierAccountSyncService.sync(accounts);
final int BATCH = 100;
for (int i = 0; i < accounts.size(); i += BATCH)
{
List<SupplierAccount> batch = accounts.subList(i, Math.min(i + BATCH, accounts.size()));
supplierAccountSyncService.sync(batch);
if (i + BATCH < accounts.size())
{
Thread.sleep(100);
}
}
}
log.info("[SupplierAccountPull] page={} total={} 本页={} 同步完成", pageNum, total, size);