/** * Returns the status (Tick::SUCCESS, Tick::FAIL, TICK::SKIP) of the last item processed * * @return int */ public function getStatus() { return $this->tick->getStatus(); }
/** * Write Log Line * * @param Tick $tick */ public function writeLogLine(Tick $tick) { // Line segments $lineSegs = array(); // 1st Segment is a star switch ($tick->getStatus()) { case Tick::SUCCESS: $lineSegs[] = sprintf("<fg=green>%s</fg=green>", $this->linePrefixMap[Tick::SUCCESS]); break; case Tick::FAIL: $lineSegs[] = sprintf("<fg=red>%s</fg=red>", $this->linePrefixMap[Tick::FAIL]); break; case Tick::SKIP: default: $lineSegs[] = $this->linePrefixMap[Tick::SKIP]; } // Item Progress $lineSegs[] = sprintf("[%s%s]", $tick->getReport()->getNumItemsProcessed(), $tick->getReport()->getTotalItemCount() != Tracker::UNKNOWN ? "/" . $tick->getReport()->getTotalItemCount() : ''); // If verbose, add walltime and item counts if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $lineSegs[] = $this->formatSeconds($tick->getReport()->getTimeElapsed()); $lineSegs[] = sprintf('(<fg=green>%s</fg=green>/%s/<fg=red>%s</fg=red>)', $tick->getReport()->getNumItemsSuccess(), $tick->getReport()->getNumItemsSkip(), $tick->getReport()->getNumItemsFail()); } // If very verbose, add memory usage if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $lineSegs[] = sprintf("{%s/%s}", $this->bytesToHuman($tick->getReport()->getMemUsage()), $this->bytesToHuman($tick->getReport()->getMemPeakUsage())); } // Add message $lineSegs[] = $tick->getMessage() ?: sprintf("Processing item %s", number_format($tick->getReport()->getNumItemsProcessed(), 0)); // Output it! $this->output->writeln(implode(' ', $lineSegs)); }
/** * Tick callback * * @param Tick $tick */ public function tick(Tick $tick) { $callback = $tick->getStatus() == Tick::FAIL ? [$this->logger, 'warning'] : [$this->logger, 'info']; $msg = sprintf("[%s/%s] %s", $tick->getReport()->getNumItemsProcessed(), $tick->getReport()->getTotalItemCount(), $tick->getMessage() ?: 'Tick'); call_user_func($callback, $msg, $tick->getReport()->toArray()); }
/** * Indicate progress to the tracker * * Builds a report and send it to the tick method in the output handlers * * @param int $status SUCCESS (default), SKIP, or FAIL * @param string $msg Message to include for this report * @param array $extraInfo * @param int $incrementBy * @return Report */ public function tick($status = Tick::SUCCESS, $msg = null, array $extraInfo = [], $incrementBy = 1) { if (!$this->isRunning()) { $this->start(); } $tick = new Tick($this, $status, $msg, $extraInfo, $incrementBy); // Increment the counter if (array_key_exists($tick->getStatus(), $this->numProcessedItems)) { $this->numProcessedItems[$tick->getStatus()] += $tick->getIncrementBy(); } else { $this->numProcessedItems[$tick->getStatus()] = $tick->getIncrementBy(); } $this->dispatcher->dispatch(Events::TRACKER_TICK, $tick); $this->lastTick = $tick; return $tick->getReport(); }