public function init()
 {
     $this->_instanceName = $this->argumentValue('instance', '');
     $this->_logger->setInstanceName($this->_instanceName);
     if ($this->argumentIsSet('dry-run')) {
         ProcessorOptions::setDryRun(true);
     }
     TokenRange::setOverrideTableName($this->_getTokenRangesTableName());
     TokenRange::setOverrideServiceName($this->_getTokenRangesDBServiceName());
 }
 private function _generatePrettyReport(TokenRange $currentRange, $now, $rangeStartTime, $rangeTotal, $rangeProcessed, $rangeErrors, $currentRate, $rangeSkipped, $totalSkipped, $totalDuration, $averageRate, $lastKey)
 {
     $t = new TextTable(new ReportTableDecorator());
     $t->appendSubHeading('Current Range ' . Shell::colourText("(" . $currentRange->id() . ")", Shell::COLOUR_FOREGROUND_LIGHT_GREY));
     $t->appendRows([['Start token', $currentRange->startToken], ['End token', $currentRange->endToken], ['First key', $currentRange->firstKey], ['Last key', $currentRange->lastKey]]);
     $t->appendSubHeading('Range statistics');
     $t->appendRows([['Processing time', DateTimeHelper::secondsToTime($now - $rangeStartTime)], ['Total items', number_format($rangeTotal)], ['Processed items', number_format($rangeProcessed)], ['Skipped', number_format($rangeSkipped)], ['Errors', number_format($rangeErrors)], ['Processing rate', number_format($currentRate) . ' items/second']]);
     $t->appendSubHeading('Total');
     $t->appendRows([['Processing time', DateTimeHelper::secondsToTime($totalDuration)], ['Total items', number_format($this->totalItems)], ['Processed items', number_format($this->processedItems)], ['Skipped', number_format($totalSkipped)], ['Errors', number_format($this->errors)], ['Processing rate', number_format($averageRate) . ' items/second']]);
     $t->appendSpacer();
     $t->appendRow(['Last key seen', $lastKey]);
     ob_start();
     echo $_REQUEST['__path__'] . "\n";
     echo $t;
     EventManager::trigger(Events::DISPLAY_REPORT_END);
     return ob_get_clean();
 }
 /**
  * Get a list of all Token Ranges tables that could be used by this script.
  * In most cases this will only return 1 table but if the script is using
  * sharded tables then this will return all of them.
  *
  * @return string[]
  */
 public function listAllRangeTables()
 {
     $tables = [];
     $db = TokenRange::conn();
     $tableName = TokenRange::tableName();
     if (strpos($tableName, '_') !== false) {
         $parts = explode("_", $tableName);
         $last = array_pop($parts);
         if (is_numeric($last)) {
             $tableBase = implode("_", $parts) . '_';
             $i = 1;
             while (true) {
                 $table = $tableBase . $i;
                 $res = $db->numRows("SHOW TABLES LIKE '" . $table . "'");
                 if ($res > 0) {
                     $tables[] = $table;
                 } else {
                     break;
                 }
                 $i++;
             }
         }
     }
     if (count($tables) == 0) {
         $tables = [$tableName];
     }
     return $tables;
 }