public function testOverwriteWithShorterLine()
 {
     $progress = new ProgressHelper();
     $progress->setFormat(' %current%/%max% [%bar%] %percent%%');
     $progress->start($output = $this->getOutputStream(), 50);
     $progress->display();
     $progress->advance();
     // set shorter format
     $progress->setFormat(' %current%/%max% [%bar%]');
     $progress->advance();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput('  0/50 [>---------------------------]   0%') . $this->generateOutput('  1/50 [>---------------------------]   2%') . $this->generateOutput('  2/50 [=>--------------------------]     '), stream_get_contents($output->getStream()));
 }
Beispiel #2
0
 /**
  * @param ProgressHelper $progress
  * @param OutputInterface $output
  * @param string $filename
  */
 public function __construct(ProgressHelper $progress, OutputInterface $output, $filename)
 {
     $progress->setFormat(ProgressHelper::FORMAT_QUIET);
     $output = new ExportOutput($output, $filename, false);
     // reset old value
     $output->write('0%');
     parent::__construct($progress, $output);
 }
Beispiel #3
0
 public function run()
 {
     foreach ($this->processes as $process) {
         /** @var $process Process  **/
         $process->setIdleTimeout($this->idleTimeout);
         $process->setTimeout($this->timeout);
         $process->start();
         $this->printTaskInfo($process->getCommandLine());
     }
     $progress = new ProgressHelper();
     $progress->setFormat(" <fg=white;bg=cyan;options=bold>[" . get_class($this) . "]</fg=white;bg=cyan;options=bold> Processes: %current%/%max% [%bar%] %percent%%");
     $progress->start($this->getOutput(), count($this->processes));
     $running = $this->processes;
     $progress->display();
     $started = microtime(true);
     while (true) {
         foreach ($running as $k => $process) {
             try {
                 $process->checkTimeout();
             } catch (ProcessTimedOutException $e) {
             }
             if (!$process->isRunning()) {
                 $progress->advance();
                 if ($this->isPrinted) {
                     $this->getOutput()->writeln("");
                     $this->printTaskInfo("Output for <fg=white;bg=magenta> " . $process->getCommandLine() . " </fg=white;bg=magenta>");
                     $this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW);
                     if ($process->getErrorOutput()) {
                         $this->getOutput()->writeln("<error>" . $process->getErrorOutput() . "</error>");
                     }
                 }
                 unset($running[$k]);
             }
         }
         if (empty($running)) {
             break;
         }
         usleep(1000);
     }
     $this->getOutput()->writeln("");
     $taken = number_format(microtime(true) - $started, 2);
     $this->printTaskInfo(count($this->processes) . " processes ended in {$taken} s");
     $errorMessage = '';
     $exitCode = 0;
     foreach ($this->processes as $p) {
         if ($p->getExitCode() === 0) {
             continue;
         }
         $errorMessage .= "'" . $p->getCommandLine() . "' exited with code " . $p->getExitCode() . " \n";
         $exitCode = max($exitCode, $p->getExitCode());
     }
     return new Result($this, $exitCode, $errorMessage);
 }
 public function testCustomizations()
 {
     $progress = new ProgressHelper();
     $progress->setBarWidth(10);
     $progress->setBarCharacter('_');
     $progress->setEmptyBarCharacter(' ');
     $progress->setProgressCharacter('/');
     $progress->setFormat(' %current%/%max% [%bar%] %percent%%');
     $progress->start($output = $this->getOutputStream(), 10);
     $progress->advance();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput('  1/10 [_/        ]  10%'), stream_get_contents($output->getStream()));
 }
Beispiel #5
0
 private function clearCache(\Elasticsearch\Client $client, OutputInterface $output)
 {
     $output->writeln('<info>Clearing filter cache (scheduled to clear in 60s)</info>');
     $size = Response::fetchFilterCache($client->indices()->stats());
     $times = 60;
     $client->indices()->clearCache(['filter' => true]);
     $progress = new ProgressHelper();
     $progress->setFormat(ProgressHelper::FORMAT_QUIET_NOMAX);
     $progress->start($output, $times);
     while (Response::fetchFilterCache($client->indices()->stats()) == $size) {
         sleep(1);
         $progress->advance();
         $times--;
         if ($times <= 0) {
             break;
         }
     }
     $progress->finish();
     $output->writeln('<info>Done cache clear.</info>');
 }