diff --git a/src/Console/Command/Io/IndexerProgressBar.php b/src/Console/Command/Io/IndexerProgressBar.php index 3041dc0..bf96aac 100644 --- a/src/Console/Command/Io/IndexerProgressBar.php +++ b/src/Console/Command/Io/IndexerProgressBar.php @@ -19,6 +19,8 @@ class IndexerProgressBar implements IndexerProgressHandler private IndexerProgressHandler $currentProgressHandler; + private int $prepareLines = 0; + /** * @var array */ @@ -37,8 +39,18 @@ public function init( $this->progressBar = null; } + public function prepare(string $message): void + { + $this->currentProgressHandler->prepare($message); + $this->output->writeln($message); + $this->prepareLines++; + } + public function start(int $total): void { + if ($this->prepareLines > 0) { + $this->output->write("\x1b[" . $this->prepareLines . "A"); + } $this->currentProgressHandler->start($total); $this->progressBar = new ProgressBar($this->output, $total); $this->formatProgressBar('green'); diff --git a/src/Dto/Indexer/IndexerStatus.php b/src/Dto/Indexer/IndexerStatus.php index bba6d45..7ea77aa 100644 --- a/src/Dto/Indexer/IndexerStatus.php +++ b/src/Dto/Indexer/IndexerStatus.php @@ -31,7 +31,8 @@ public function __construct( public int $skipped, public DateTime $lastUpdate, public int $updated, - public int $errors + public int $errors, + public string $prepareMessage = '' ) { } @@ -53,6 +54,7 @@ public static function empty(): IndexerStatus public function getStatusLine(): string { + $endTime = $this->endTime; if ($endTime === null || $endTime->getTimestamp() === 0) { $endTime = new DateTime(); @@ -63,6 +65,15 @@ public function getStatusLine(): string if ($lastUpdate->getTimestamp() === 0) { $lastUpdate = $endTime; } + + if ($this->state === IndexerStatusState::PREPARING) { + return + '[' . $this->state->name . '] ' . + 'start: ' . $this->startTime->format('d.m.Y H:i') . ', ' . + 'time: ' . $duration->format('%Hh %Im %Ss') . ', ' . + 'message: ' . $this->prepareMessage; + } + return '[' . $this->state->name . '] ' . 'start: ' . $this->startTime->format('d.m.Y H:i') . ', ' . diff --git a/src/Dto/Indexer/IndexerStatusState.php b/src/Dto/Indexer/IndexerStatusState.php index 2a7c19d..8e22865 100644 --- a/src/Dto/Indexer/IndexerStatusState.php +++ b/src/Dto/Indexer/IndexerStatusState.php @@ -10,6 +10,7 @@ enum IndexerStatusState: string { case UNKNOWN = 'UNKNOWN'; + case PREPARING = 'PREPARING'; case RUNNING = 'RUNNING'; case FINISHED = 'FINISHED'; case ABORTED = 'ABORTED'; diff --git a/src/Service/Indexer/IndexerProgressHandler.php b/src/Service/Indexer/IndexerProgressHandler.php index 49449e8..58c00b4 100644 --- a/src/Service/Indexer/IndexerProgressHandler.php +++ b/src/Service/Indexer/IndexerProgressHandler.php @@ -9,6 +9,7 @@ interface IndexerProgressHandler { + public function prepare(string $message): void; public function start(int $total): void; public function startUpdate(int $total): void; public function advance(int $step): void; diff --git a/src/Service/Indexer/IndexerProgressState.php b/src/Service/Indexer/IndexerProgressState.php index 7fec343..56df104 100644 --- a/src/Service/Indexer/IndexerProgressState.php +++ b/src/Service/Indexer/IndexerProgressState.php @@ -25,11 +25,38 @@ public function __construct( ) { } + public function prepare(string $message): void + { + $this->status = new IndexerStatus( + IndexerStatusState::PREPARING, + new DateTime(), + null, + 0, + 0, + 0, + new DateTime(), + 0, + 0, + $message + ); + $this->statusStore->store( + $this->getStatusStoreKey(), + $this->status + ); + } + public function start(int $total): void { + $storedStatus = $this->statusStore->load($this->getStatusStoreKey()); + + $startTime = new DateTime(); + if ($storedStatus->state === IndexerStatusState::PREPARING) { + $startTime = $storedStatus->startTime; + } + $this->status = new IndexerStatus( IndexerStatusState::RUNNING, - new DateTime(), + $startTime, null, $total, 0, @@ -38,6 +65,10 @@ public function start(int $total): void 0, 0 ); + $this->statusStore->store( + $this->getStatusStoreKey(), + $this->status + ); } /** @@ -58,6 +89,10 @@ public function startUpdate(int $total): void $storedStatus->updated, $storedStatus->errors, ); + $this->statusStore->store( + $this->getStatusStoreKey(), + $this->status + ); } public function advance(int $step): void diff --git a/src/Service/Indexer/InternalResourceIndexer.php b/src/Service/Indexer/InternalResourceIndexer.php index 24b2b2f..a372961 100644 --- a/src/Service/Indexer/InternalResourceIndexer.php +++ b/src/Service/Indexer/InternalResourceIndexer.php @@ -132,6 +132,9 @@ public function index(): IndexerStatus 'chunkSize' => $param->chunkSize, 'cleanupThreshold' => $param->cleanupThreshold, ]); + + $this->progressHandler->prepare('Collect resource locations'); + try { $paths = $this->finder->findAll(); $this->deleteErrorProtocol($this->getBaseIndex());