Skip to content

Commit 474974c

Browse files
Add support for --queue option to scout:queue-import (#932)
* Add support for `--queue` option to `scout:queue-import` * Add shorthand option * Remove shorthand option (clashes with --quiet, oops) * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2d9f852 commit 474974c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/Console/QueueImportCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class QueueImportCommand extends Command
1818
{model : Class name of model to bulk queue}
1919
{--min= : The minimum ID to start queuing from}
2020
{--max= : The maximum ID to queue up to}
21-
{--c|chunk= : The number of records to queue in a single job (Defaults to configuration value: `scout.chunk.searchable`)}';
21+
{--c|chunk= : The number of records to queue in a single job (Defaults to configuration value: `scout.chunk.searchable`)}
22+
{--queue= : The queue that should be used (Defaults to configuration value: `scout.queue.queue`)}';
2223

2324
/**
2425
* The console command description.
@@ -61,7 +62,7 @@ public function handle()
6162
$end = min($start + $chunk - 1, $max);
6263

6364
dispatch(new MakeRangeSearchable($class, $start, $end))
64-
->onQueue($model->syncWithSearchUsingQueue())
65+
->onQueue($this->option('queue') ?? $model->syncWithSearchUsingQueue())
6566
->onConnection($model->syncWithSearchUsing());
6667

6768
$this->line('<comment>Queued ['.$class.'] models up to ID:</comment> '.$end);

tests/Feature/Commands/QueueImportCommandTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,25 @@ public function test_it_handles_negative_min_option()
399399
});
400400
}
401401

402+
public function test_it_accepts_custom_queue_option()
403+
{
404+
Queue::fake();
405+
406+
SearchableUserFactory::new()->count(10)->create();
407+
408+
$this->artisan('scout:queue-import', [
409+
'model' => SearchableUser::class,
410+
'--queue' => 'custom-queue',
411+
])
412+
->expectsOutputToContain('models up to ID: 10')
413+
->expectsOutputToContain('records have been queued')
414+
->assertSuccessful();
415+
416+
Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) {
417+
return $job->start == 1 && $job->end == 10;
418+
});
419+
}
420+
402421
public function test_it_can_accept_all_options()
403422
{
404423
Queue::fake();
@@ -410,6 +429,7 @@ public function test_it_can_accept_all_options()
410429
'--min' => 5,
411430
'--max' => 15,
412431
'--chunk' => 4,
432+
'--queue' => 'custom-queue',
413433
])
414434
->expectsOutputToContain('models up to ID: 8')
415435
->expectsOutputToContain('models up to ID: 12')
@@ -419,5 +439,17 @@ public function test_it_can_accept_all_options()
419439

420440
// Should dispatch 3 jobs: [5-8], [9-12], [13-15]
421441
Queue::assertPushed(MakeRangeSearchable::class, 3);
442+
443+
Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) {
444+
return $job->start == 5 && $job->end == 8;
445+
});
446+
447+
Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) {
448+
return $job->start == 9 && $job->end == 12;
449+
});
450+
451+
Queue::assertPushedOn('custom-queue', MakeRangeSearchable::class, function ($job) {
452+
return $job->start == 13 && $job->end == 15;
453+
});
422454
}
423455
}

0 commit comments

Comments
 (0)