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