diff --git a/src/Console/QueueImportCommand.php b/src/Console/QueueImportCommand.php index 7db9e513..14493518 100644 --- a/src/Console/QueueImportCommand.php +++ b/src/Console/QueueImportCommand.php @@ -18,7 +18,8 @@ class QueueImportCommand extends Command {model : Class name of model to bulk queue} {--min= : The minimum ID to start queuing from} {--max= : The maximum ID to queue up to} - {--c|chunk= : The number of records to queue in a single job (Defaults to configuration value: `scout.chunk.searchable`)}'; + {--c|chunk= : The number of records to queue in a single job (Defaults to configuration value: `scout.chunk.searchable`)} + {--queue= : The queue that should be used (Defaults to configuration value: `scout.queue.queue`)}'; /** * The console command description. @@ -61,7 +62,7 @@ public function handle() $end = min($start + $chunk - 1, $max); dispatch(new MakeRangeSearchable($class, $start, $end)) - ->onQueue($model->syncWithSearchUsingQueue()) + ->onQueue($this->option('queue') ?? $model->syncWithSearchUsingQueue()) ->onConnection($model->syncWithSearchUsing()); $this->line('Queued ['.$class.'] models up to ID: '.$end); diff --git a/tests/Feature/Commands/QueueImportCommandTest.php b/tests/Feature/Commands/QueueImportCommandTest.php index 63fc5296..a68ef247 100644 --- a/tests/Feature/Commands/QueueImportCommandTest.php +++ b/tests/Feature/Commands/QueueImportCommandTest.php @@ -399,6 +399,25 @@ public function test_it_handles_negative_min_option() }); } + public function test_it_accepts_custom_queue_option() + { + Queue::fake(); + + SearchableUserFactory::new()->count(10)->create(); + + $this->artisan('scout:queue-import', [ + 'model' => SearchableUser::class, + '--queue' => 'custom-queue', + ]) + ->expectsOutputToContain('models up to ID: 10') + ->expectsOutputToContain('records have been queued') + ->assertSuccessful(); + + Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) { + return $job->start == 1 && $job->end == 10; + }); + } + public function test_it_can_accept_all_options() { Queue::fake(); @@ -410,6 +429,7 @@ public function test_it_can_accept_all_options() '--min' => 5, '--max' => 15, '--chunk' => 4, + '--queue' => 'custom-queue', ]) ->expectsOutputToContain('models up to ID: 8') ->expectsOutputToContain('models up to ID: 12') @@ -419,5 +439,17 @@ public function test_it_can_accept_all_options() // Should dispatch 3 jobs: [5-8], [9-12], [13-15] Queue::assertPushed(MakeRangeSearchable::class, 3); + + Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) { + return $job->start == 5 && $job->end == 8; + }); + + Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) { + return $job->start == 9 && $job->end == 12; + }); + + Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) { + return $job->start == 13 && $job->end == 15; + }); } }