Fixes for errors when with the progress closure

This commit is contained in:
Tim Nagel 2015-03-11 21:31:23 +11:00
parent 4a564401b4
commit 0009c858a7
3 changed files with 18 additions and 3 deletions

View file

@ -35,12 +35,18 @@ class ProgressClosureBuilder
$progress = null;
return function ($increment, $totalObjects) use (&$progress, $output, $action, $index, $type) {
return function ($increment, $totalObjects, $message = null) use (&$progress, $output, $action, $index, $type) {
if (null === $progress) {
$progress = new ProgressBar($output, $totalObjects);
$progress->start();
}
if (null !== $message) {
$progress->clear();
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
$progress->display();
}
$progress->setMessage(sprintf('<info>%s</info> <comment>%s/%s</comment>', $action, $index, $type));
$progress->advance($increment);
};
@ -62,11 +68,15 @@ class ProgressClosureBuilder
$lastStep = null;
$current = 0;
return function ($increment, $totalObjects) use ($output, $action, $index, $type, &$lastStep, &$current) {
return function ($increment, $totalObjects, $message = null) use ($output, $action, $index, $type, &$lastStep, &$current) {
if ($current + $increment > $totalObjects) {
$increment = $totalObjects - $current;
}
if (null !== $message) {
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
}
$currentTime = microtime(true);
$timeDifference = $currentTime - $lastStep;
$objectsPerSecond = $lastStep ? ($increment / $timeDifference) : $increment;

View file

@ -67,7 +67,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
$this->objectPersister->insertMany($objects);
} catch(BulkResponseException $e) {
if ($loggerClosure) {
$loggerClosure(sprintf('<error>%s</error>',$e->getMessage()));
$loggerClosure($batchSize, $nbObjects, sprintf('<error>%s</error>', $e->getMessage()));
}
}
}

View file

@ -12,6 +12,11 @@ interface ProviderInterface
/**
* Persists all domain objects to ElasticSearch for this provider.
*
* The closure can expect 2 or 3 arguments:
* * The step size
* * The total number of objects
* * A message to output in error conditions (not normally provided)
*
* @param \Closure $loggerClosure
* @param array $options
* @return