From 1e583a660da2411f8227dc026a99eeddeecf14a7 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Mon, 19 Oct 2026 14:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=94=9F=E4=BA=A7=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E7=AE=97=E7=94=B1=E5=8F=97=E9=99=90=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=B9=E5=99=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/upstream_pipeline.php | 1 + .../AccountMappingResyncDispatcher.php | 7 ++++- .../AccountMappingResyncDispatcherTest.php | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/config/upstream_pipeline.php b/config/upstream_pipeline.php index b1c515bd..8d38f572 100644 --- a/config/upstream_pipeline.php +++ b/config/upstream_pipeline.php @@ -1,6 +1,7 @@ (bool) env('FINANCE_BATCH_WORKER_ENABLED', false), // Connection records supply addresses and credentials, never these defaults. 'defaults' => ['enabled' => false, 'connection' => ['connect_timeout' => 5, 'query_timeout' => 15]], 'sync' => [ diff --git a/modules/EcommerceFinance/Services/AccountMappingResyncDispatcher.php b/modules/EcommerceFinance/Services/AccountMappingResyncDispatcher.php index f9ad9921..13aa7922 100644 --- a/modules/EcommerceFinance/Services/AccountMappingResyncDispatcher.php +++ b/modules/EcommerceFinance/Services/AccountMappingResyncDispatcher.php @@ -102,10 +102,15 @@ class AccountMappingResyncDispatcher public function spawnWorker(): void { // Production cron consumes the durable queue in the resource-limited batch profile. - if (filter_var(env('FINANCE_BATCH_WORKER_ENABLED', false), FILTER_VALIDATE_BOOL)) { + if (config('upstream_pipeline.batch_worker_enabled', false)) { return; } + $this->launchWorker(); + } + + protected function launchWorker(): void + { try { $php = escapeshellarg(PHP_BINARY ?: 'php'); $command = 'cd ' . escapeshellarg(base_path()) diff --git a/tests/Unit/EcommerceFinance/AccountMappingResyncDispatcherTest.php b/tests/Unit/EcommerceFinance/AccountMappingResyncDispatcherTest.php index 640c3f92..d54f45ef 100644 --- a/tests/Unit/EcommerceFinance/AccountMappingResyncDispatcherTest.php +++ b/tests/Unit/EcommerceFinance/AccountMappingResyncDispatcherTest.php @@ -8,6 +8,36 @@ use Tests\TestCase; class AccountMappingResyncDispatcherTest extends TestCase { + public function test_production_leaves_queue_processing_to_the_limited_batch_worker(): void + { + config(['upstream_pipeline.batch_worker_enabled' => true]); + $dispatcher = $this->recordingDispatcher(); + $dispatcher->spawnWorker(); + + $this->assertSame(0, $dispatcher->launches); + } + + public function test_local_development_still_launches_an_immediate_worker(): void + { + config(['upstream_pipeline.batch_worker_enabled' => false]); + $dispatcher = $this->recordingDispatcher(); + $dispatcher->spawnWorker(); + + $this->assertSame(1, $dispatcher->launches); + } + + private function recordingDispatcher(): AccountMappingResyncDispatcher + { + return new class extends AccountMappingResyncDispatcher { + public int $launches = 0; + + protected function launchWorker(): void + { + $this->launches++; + } + }; + } + public function test_all_taobao_family_platforms_trigger_the_matching_receipt_sources(): void { $reflection = new ReflectionClass(AccountMappingResyncDispatcher::class);