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)); + } } } }