public static function waitAndLog(Activity $activity, OutputInterface $output, $success = null, $failure = null)
{
$output->writeln('Waiting for the activity <info>' . $activity->id . '</info> (' . $activity->getDescription() . "):");
// Initialize a progress bar which will show elapsed time and the
// activity's state.
$bar = new ProgressBar($output);
$bar->setPlaceholderFormatterDefinition('state', function () use($activity) {
return self::formatState($activity->state);
});
$bar->setFormat(" [%bar%] %elapsed:6s% (%state%)");
$bar->start();
// Wait for the activity to complete.
$activity->wait(function () use($bar) {
$bar->advance();
}, function ($log) use($output, $bar) {
// Clear the progress bar and ensure the current line is flushed.
$bar->clear();
$output->write($output->isDecorated() ? "\n[1A" : "\n");
// Display the new log output, with an indent.
$output->write(preg_replace('/^/m', ' ', $log));
// Display the progress bar again.
$bar->advance();
});
$bar->finish();
$output->writeln('');
// Display the success or failure messages.
switch ($activity['result']) {
case Activity::RESULT_SUCCESS:
$output->writeln($success ?: "Activity <info>{$activity->id}</info> succeeded");
return true;
case Activity::RESULT_FAILURE:
$output->writeln($failure ?: "Activity <error>{$activity->id}</error> failed");
return false;
}
return false;
}