Skip to content

Add support for --queue option to scout:queue-import #932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Console/QueueImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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('<comment>Queued ['.$class.'] models up to ID:</comment> '.$end);
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/Commands/QueueImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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')
Expand All @@ -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;
});
}
}