-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from matchish/progress
Add progress report
- Loading branch information
Showing
39 changed files
with
803 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'done' => 'All [:searchable] records have been flushed.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
'start' => 'Importing [:searchable]', | ||
'done' => 'All [:searchable] records have been imported.', | ||
'done.queue' => 'Import job dispatched to the queue.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Matchish\ScoutElasticSearch\Console\Commands; | ||
|
||
use Symfony\Component\Console\Style\OutputStyle; | ||
|
||
class ProgressBarFactory | ||
{ | ||
/** | ||
* @var OutputStyle | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* @param OutputStyle $output | ||
*/ | ||
public function __construct(OutputStyle $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
public function create(int $max = 0) | ||
{ | ||
$bar = $this->output->createProgressBar($max); | ||
$bar->setBarCharacter('<fg=green>⚬</>'); | ||
$bar->setEmptyBarCharacter('<fg=red>⚬</>'); | ||
$bar->setProgressCharacter('<fg=green>➤</>'); | ||
$bar->setFormat( | ||
"%message%\n%current%/%max% [%bar%] %percent:3s%%\n" | ||
); | ||
|
||
return $bar; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Matchish\ScoutElasticSearch\Jobs; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Matchish\ScoutElasticSearch\ElasticSearch\Index; | ||
use Matchish\ScoutElasticSearch\Jobs\Stages\CleanUp; | ||
use Matchish\ScoutElasticSearch\Jobs\Stages\RefreshIndex; | ||
use Matchish\ScoutElasticSearch\Jobs\Stages\PullFromSource; | ||
use Matchish\ScoutElasticSearch\Jobs\Stages\CreateWriteIndex; | ||
use Matchish\ScoutElasticSearch\Jobs\Stages\SwitchToNewAndRemoveOldIndex; | ||
|
||
class ImportStages extends Collection | ||
{ | ||
/** | ||
* @param Model $searchable | ||
* @return Collection | ||
*/ | ||
public static function fromSearchable(Model $searchable) | ||
{ | ||
$index = Index::fromSearchable($searchable); | ||
$main = PullFromSource::chunked($searchable); | ||
if ($main->count()) { | ||
return (new static([ | ||
new CleanUp($searchable), | ||
new CreateWriteIndex($searchable, $index), | ||
PullFromSource::chunked($searchable), | ||
new RefreshIndex($index), | ||
new SwitchToNewAndRemoveOldIndex($searchable, $index), | ||
]))->flatten(); | ||
} else { | ||
return new static; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Matchish\ScoutElasticSearch\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Matchish\ScoutElasticSearch\ProgressReportable; | ||
|
||
class QueueableJob implements ShouldQueue | ||
{ | ||
use Queueable; | ||
use ProgressReportable; | ||
|
||
public function handle() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Matchish\ScoutElasticSearch\Jobs\Stages; | ||
|
||
use Elasticsearch\Client; | ||
use Laravel\Scout\Searchable; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Elasticsearch\Common\Exceptions\Missing404Exception; | ||
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Alias\Get as GetAliasParams; | ||
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Delete as DeleteIndexParams; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CleanUp | ||
{ | ||
/** | ||
* @var Model | ||
*/ | ||
private $searchable; | ||
|
||
/** | ||
* @param Model $searchable | ||
*/ | ||
public function __construct(Model $searchable) | ||
{ | ||
$this->searchable = $searchable; | ||
} | ||
|
||
public function handle(Client $elasticsearch): void | ||
{ | ||
/** @var Searchable $searchable */ | ||
$searchable = $this->searchable; | ||
$params = GetAliasParams::anyIndex($searchable->searchableAs()); | ||
try { | ||
$response = $elasticsearch->indices()->getAliases($params->toArray()); | ||
} catch (Missing404Exception $e) { | ||
$response = []; | ||
} | ||
foreach ($response as $indexName => $data) { | ||
foreach ($data['aliases'] as $alias => $config) { | ||
if (array_key_exists('is_write_index', $config) && $config['is_write_index']) { | ||
$params = new DeleteIndexParams((string) $indexName); | ||
$elasticsearch->indices()->delete($params->toArray()); | ||
continue 2; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public function title(): string | ||
{ | ||
return 'Clean up'; | ||
} | ||
|
||
public function estimate(): int | ||
{ | ||
return 1; | ||
} | ||
} |
Oops, something went wrong.