Skip to content
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

stage interface improvement for stages #261

Merged
merged 3 commits into from
Oct 12, 2023
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
2 changes: 2 additions & 0 deletions src/Jobs/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Elastic\Elasticsearch\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Collection;
use Matchish\ScoutElasticSearch\Jobs\Stages\StageInterface;
use Matchish\ScoutElasticSearch\ProgressReportable;
use Matchish\ScoutElasticSearch\Searchable\ImportSource;

Expand Down Expand Up @@ -40,6 +41,7 @@ public function handle(Client $elasticsearch): void
$estimate = $stages->sum->estimate();
$this->progressBar()->setMaxSteps($estimate);
$stages->each(function ($stage) use ($elasticsearch) {
/** @var StageInterface $stage */
$this->progressBar()->setMessage($stage->title());
$stage->handle($elasticsearch);
$this->progressBar()->advance($stage->estimate());
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Stages/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @internal
*/
final class CleanUp
final class CleanUp implements StageInterface
{
/**
* @var ImportSource
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Stages/CreateWriteIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @internal
*/
final class CreateWriteIndex
final class CreateWriteIndex implements StageInterface
{
/**
* @var ImportSource
Expand Down
5 changes: 3 additions & 2 deletions src/Jobs/Stages/PullFromSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Matchish\ScoutElasticSearch\Jobs\Stages;

use Elastic\Elasticsearch\Client;
use Illuminate\Support\Collection;
use Matchish\ScoutElasticSearch\Searchable\ImportSource;

/**
* @internal
*/
final class PullFromSource
final class PullFromSource implements StageInterface
{
/**
* @var ImportSource
Expand All @@ -23,7 +24,7 @@ public function __construct(ImportSource $source)
$this->source = $source;
}

public function handle(): void
public function handle(Client $elasticsearch = null): void
{
$results = $this->source->get()->filter->shouldBeSearchable();
if (! $results->isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Stages/RefreshIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @internal
*/
final class RefreshIndex
final class RefreshIndex implements StageInterface
{
/**
* @var Index
Expand Down
12 changes: 12 additions & 0 deletions src/Jobs/Stages/StageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Matchish\ScoutElasticSearch\Jobs\Stages;

use Elastic\Elasticsearch\Client;

interface StageInterface
{
public function title(): string;
public function estimate(): int;
public function handle(Client $elasticsearch): void;
}
2 changes: 1 addition & 1 deletion src/Jobs/Stages/SwitchToNewAndRemoveOldIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @internal
*/
final class SwitchToNewAndRemoveOldIndex
final class SwitchToNewAndRemoveOldIndex implements StageInterface
{
/**
* @var ImportSource
Expand Down