Skip to content

Commit

Permalink
Merge pull request #261 from hkulekci/initialized-stage-interface
Browse files Browse the repository at this point in the history
stage interface improvement for stages
  • Loading branch information
matchish authored Oct 12, 2023
2 parents 0a5dfc8 + ce1cf4e commit d76fa8b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
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

0 comments on commit d76fa8b

Please sign in to comment.