force queue

This commit is contained in:
Daniel Klabbers 2021-11-04 10:47:24 +01:00
parent 33ae86a539
commit 4c056a4db4
2 changed files with 5 additions and 3 deletions

View File

@ -2,6 +2,7 @@
namespace Blomstra\Search\Commands; namespace Blomstra\Search\Commands;
use Blomstra\Search\Jobs\Job;
use Blomstra\Search\Jobs\SavingJob; use Blomstra\Search\Jobs\SavingJob;
use Blomstra\Search\Seeders\Seeder; use Blomstra\Search\Seeders\Seeder;
use Elasticsearch\Client; use Elasticsearch\Client;
@ -80,7 +81,7 @@ class BuildCommand extends Command
$query->where('id', '<=', $id); $query->where('id', '<=', $id);
}) })
->chunk(50, function (Collection $collection) use ($queue, &$total, $seeder) { ->chunk(50, function (Collection $collection) use ($queue, &$total, $seeder) {
$queue->push(new SavingJob($collection, $seeder)); $queue->pushOn(Job::$onQueue, new SavingJob($collection, $seeder));
$this->info("Pushed into the index, type: {$seeder->type()}, amount: {$collection->count()}."); $this->info("Pushed into the index, type: {$seeder->type()}, amount: {$collection->count()}.");

View File

@ -3,6 +3,7 @@
namespace Blomstra\Search; namespace Blomstra\Search;
use Blomstra\Search\Jobs\DeletingJob; use Blomstra\Search\Jobs\DeletingJob;
use Blomstra\Search\Jobs\Job;
use Blomstra\Search\Jobs\SavingJob; use Blomstra\Search\Jobs\SavingJob;
use Blomstra\Search\Seeders; use Blomstra\Search\Seeders;
use Elasticsearch\Client; use Elasticsearch\Client;
@ -63,11 +64,11 @@ class Provider extends AbstractServiceProvider
/** @var string|Seeders\Seeder $seeder */ /** @var string|Seeders\Seeder $seeder */
foreach ($seeders as $seeder) { foreach ($seeders as $seeder) {
$seeder::savingOn($events, function ($model) use ($queue, $seeder) { $seeder::savingOn($events, function ($model) use ($queue, $seeder) {
$queue->push(new SavingJob(Collection::make([$model]), $seeder)); $queue->pushOn(Job::$onQueue, new SavingJob(Collection::make([$model]), $seeder));
}); });
$seeder::deletingOn($events, function ($model) use ($queue, $seeder) { $seeder::deletingOn($events, function ($model) use ($queue, $seeder) {
$queue->push(new DeletingJob(Collection::make([$model]), $seeder)); $queue->pushOn(Job::$onQueue, new DeletingJob(Collection::make([$model]), $seeder));
}); });
} }
} }