From c8eb6e2e5fa8fc0d249878b8450ffa299f4632c4 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Mon, 12 Oct 2026 14:39:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=8F=91=E8=B4=A7=E6=95=B0=E6=8D=AE):=20?= =?UTF-8?q?=E6=97=A9=E4=B8=8A=E8=A1=A5=E8=B7=91=E4=B8=80=E6=AC=A1=E5=8F=91?= =?UTF-8?q?=E8=B4=A7=E5=90=8C=E6=AD=A5=EF=BC=8C=E5=89=AF=E6=9C=AC=E5=BA=93?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=87=8D=E8=BF=9E=E6=94=B9=E4=B8=BA=E9=80=90?= =?UTF-8?q?=E6=AC=A1=E6=8B=89=E9=95=BF=E7=AD=89=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 凌晨 01:28 同步时副本库最近一两天的订单/商品明细常未到齐,10-12 凌晨一轮写入 4,669 个只有单号、缺商品明细的包裹 (10.10/10.11);工作平台导出为实时查询不受影响。新增每天 07:28 再拉最近 3 天,补齐商品明细。 - selectWithReconnect:副本库超时/游标失败的重试由 2 次(间隔 0.25 秒)改为 5 次,等待 2/5/10/20/30 秒, 白天整月重跑不再因单次超时中断(单测环境不等待)。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014nvGZkg27YMEdhry6eiuwf --- app/Console/Kernel.php | 6 ++++++ .../Services/Jushuitan/ShippingReplicaSynchronizer.php | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d7ef3708..43feda7a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -84,6 +84,12 @@ class Kernel extends ConsoleKernel ->dailyAt('01:28') ->withoutOverlapping(120) ->runInBackground(); + // 凌晨副本库最近一两天的订单/商品明细常未到齐(视图、订单商品表滞后), + // 早上再拉一次最近 3 天,补齐凌晨只写入单号、缺商品明细的包裹。 + $schedule->command('jushuitan:sync-shipping --days=3') + ->dailyAt('07:28') + ->withoutOverlapping(120) + ->runInBackground(); } } diff --git a/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php b/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php index b0e1175a..b93884eb 100644 --- a/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php +++ b/modules/EcommerceFinance/Services/Jushuitan/ShippingReplicaSynchronizer.php @@ -25,7 +25,9 @@ use Throwable; */ class ShippingReplicaSynchronizer { - private const UPSTREAM_RECONNECT_RETRIES = 2; + private const UPSTREAM_RECONNECT_RETRIES = 5; + /** 副本库繁忙超时后的重连等待(毫秒):逐次拉长,白天整月重跑不再因单次超时中断 */ + private const UPSTREAM_RECONNECT_BACKOFF_MS = [2000, 5000, 10000, 20000, 30000]; private const SOURCE = 'operations_replica'; private const DATASET = 'jst.sctrade'; @@ -586,7 +588,9 @@ class ShippingReplicaSynchronizer // select() returns only after fetchAll(), so no partial result was consumed. UpstreamConnection::reset(self::SOURCE); - usleep(250000); + if (! app()->runningUnitTests()) { + usleep(1000 * (self::UPSTREAM_RECONNECT_BACKOFF_MS[$retry] ?? 30000)); + } } } }