diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-08-03 20:49:41 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-08-03 20:49:41 +0300 |
commit | 5b2a63a462e920e0f745c826bdb9fd252c66acec (patch) | |
tree | 7f06f37668a01e9c8e91f74dbb854ee98a3c8b7f /lib | |
parent | b023c7e87810cda9e935c5011f7494e7570de994 (diff) |
display status
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Command/Index.php | 163 | ||||
-rw-r--r-- | lib/Service/IndexService.php | 18 |
2 files changed, 106 insertions, 75 deletions
diff --git a/lib/Command/Index.php b/lib/Command/Index.php index d95cada..b49f7e1 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -63,8 +63,8 @@ class Index extends ExtendedBase { const PANEL_STATUS = 'status'; const PANEL_STATUS_LINE_HEADER = '┌─ Status ────'; - const PANEL_STATUS_LINE_DOCUMENTS_TOTAL = '│ Total document for this user:'; - const PANEL_STATUS_LINE_DOCUMENTS_LEFT = '│ Document left:'; + const PANEL_STATUS_LINE_DOCUMENTS = '│ Progress: %documentLeft:6s%/%documentTotal%'; +// const PANEL_STATUS_LINE_DOCUMENTS_LEFT = '│ Document left:'; const PANEL_STATUS_LINE_ERRORS = '│ Errors:'; const PANEL_STATUS_LINE_FOOTER = '└──'; @@ -178,83 +178,14 @@ class Index extends ExtendedBase { $this->indexService->setRunner($this->runner); $this->cliService->setRunner($this->runner); - $this->cliService->createPanel( - self::PANEL_RUN, - [ - self::PANEL_RUN_LINE_OPTIONS, - self::PANEL_RUN_LINE_MEMORY - ] - ); - $this->cliService->createPanel( - self::PANEL_INDEX, [ - self::PANEL_INDEX_LINE_HEADER, - self::PANEL_INDEX_LINE_ACCOUNT, - self::PANEL_INDEX_LINE_ACTION, - self::PANEL_INDEX_LINE_DOCUMENT, - self::PANEL_INDEX_LINE_INFO, - self::PANEL_INDEX_LINE_TITLE, - self::PANEL_INDEX_LINE_CONTENT, - self::PANEL_INDEX_LINE_RESULT, - self::PANEL_INDEX_LINE_FOOTER, - ] - ); - - $this->cliService->createPanel( - self::PANEL_STATUS, [ - self::PANEL_STATUS_LINE_HEADER, - self::PANEL_STATUS_LINE_DOCUMENTS_TOTAL, - self::PANEL_STATUS_LINE_DOCUMENTS_LEFT, - self::PANEL_STATUS_LINE_ERRORS, - self::PANEL_LINE_EMPTY, - self::PANEL_LINE_EMPTY, - self::PANEL_LINE_EMPTY, - self::PANEL_STATUS_LINE_FOOTER, - ] - ); - - $this->cliService->createPanel( - self::PANEL_COMMANDS_ROOT, [ - self::PANEL_COMMANDS_ROOT_LINE - ] - ); - - $this->cliService->createPanel( - self::PANEL_COMMANDS_PAUSED, [ - self::PANEL_COMMANDS_PAUSED_LINE - ] - ); - - - $this->cliService->initDisplay(); - $this->cliService->displayPanel('run', self::PANEL_RUN); - $this->cliService->displayPanel('topPanel', self::PANEL_INDEX); - $this->cliService->displayPanel('bottomPanel', self::PANEL_STATUS); - - if ($this->runner->isPaused()) { - $this->cliService->displayPanel('commands', self::PANEL_COMMANDS_PAUSED); - } else { - $this->cliService->displayPanel('commands', self::PANEL_COMMANDS_ROOT); - } + $this->generatePanels(); + $this->runner->setInfo('options', json_encode($options)); try { $this->runner->sourceIsCommandLine($this, $output); $this->runner->start(); - $this->cliService->runDisplay( - $output, [ - 'userId' => '', - 'providerName' => '', - '_memory' => '', - 'documentId' => '', - 'action' => '', - 'info' => '', - 'title' => '', - '_paused' => '', - 'content' => '', - 'resultColored' => '', - 'options' => json_encode($options) - ] - ); + $this->cliService->runDisplay($output); $providers = $this->providerService->getProviders(); foreach ($providers as $provider) { @@ -263,7 +194,6 @@ class Index extends ExtendedBase { continue; } -// $this->runner->output('indexing ' . $provider->getName() . '.'); $provider->setRunner($this->runner); $provider->setIndexOptions($options); $this->indexProvider($provider, $options); @@ -274,6 +204,7 @@ class Index extends ExtendedBase { throw $e; } + $output->writeLn('done.'); $this->runner->stop(); } @@ -403,6 +334,88 @@ class Index extends ExtendedBase { return $this->userManager->search(''); } + + + /** + * + */ + private function generatePanels() { + + $this->cliService->createPanel( + self::PANEL_RUN, + [ + self::PANEL_RUN_LINE_OPTIONS, + self::PANEL_RUN_LINE_MEMORY + ] + ); + $this->cliService->createPanel( + self::PANEL_INDEX, [ + self::PANEL_INDEX_LINE_HEADER, + self::PANEL_INDEX_LINE_ACCOUNT, + self::PANEL_INDEX_LINE_ACTION, + self::PANEL_INDEX_LINE_DOCUMENT, + self::PANEL_INDEX_LINE_INFO, + self::PANEL_INDEX_LINE_TITLE, + self::PANEL_INDEX_LINE_CONTENT, + self::PANEL_INDEX_LINE_RESULT, + self::PANEL_INDEX_LINE_FOOTER, + ] + ); + + $this->cliService->createPanel( + self::PANEL_STATUS, [ + self::PANEL_STATUS_LINE_HEADER, + self::PANEL_STATUS_LINE_DOCUMENTS, + self::PANEL_STATUS_LINE_ERRORS, + self::PANEL_LINE_EMPTY, + self::PANEL_LINE_EMPTY, + self::PANEL_LINE_EMPTY, + self::PANEL_STATUS_LINE_FOOTER, + ] + ); + + $this->cliService->createPanel( + self::PANEL_COMMANDS_ROOT, [ + self::PANEL_COMMANDS_ROOT_LINE + ] + ); + + $this->cliService->createPanel( + self::PANEL_COMMANDS_PAUSED, [ + self::PANEL_COMMANDS_PAUSED_LINE + ] + ); + + + $this->cliService->initDisplay(); + $this->cliService->displayPanel('run', self::PANEL_RUN); + $this->cliService->displayPanel('topPanel', self::PANEL_INDEX); + $this->cliService->displayPanel('bottomPanel', self::PANEL_STATUS); + + if ($this->runner->isPaused()) { + $this->cliService->displayPanel('commands', self::PANEL_COMMANDS_PAUSED); + } else { + $this->cliService->displayPanel('commands', self::PANEL_COMMANDS_ROOT); + } + + $this->runner->setInfoArray( + [ + 'userId' => '', + 'providerName' => '', + '_memory' => '', + 'documentId' => '', + 'action' => '', + 'info' => '', + 'title' => '', + '_paused' => '', + 'content' => '', + 'resultColored' => '', + 'documentLeft' => '', + 'documentTotal' => '' + ] + ); + } + } diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 26866fe..c81bc77 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -156,10 +156,23 @@ class IndexService { $documents = $provider->generateIndexableDocuments($userId); + $this->updateRunnerInfoArray( + [ + 'documentTotal' => sizeof($documents), + 'documentLeft' => '' + ] + ); + //$maxSize = sizeof($documents); $toIndex = $this->updateDocumentsWithCurrIndex($provider, $documents, $options); $this->indexChunks($platform, $provider, $toIndex); + +// $this->updateRunnerInfoArray( +// [ +// 'documentLeft' => 0 +// ] +// ); } @@ -253,14 +266,19 @@ class IndexService { for ($i = 0; $i < $max; $i++) { $this->updateRunnerAction('indexChunk', true); try { + $chunk = array_splice($documents, 0, $chunkSize); $this->indexChunk($platform, $provider, $chunk); + $this->updateRunnerInfoArray(['documentLeft' => sizeof($documents)]); + /** @var IndexDocument $doc */ foreach ($chunk as $doc) { $doc->__destruct(); // because. } } catch (NoResultException $e) { + $this->updateRunnerInfoArray(['documentLeft' => 0]); + return; } catch (Exception $e) { throw $e; |