Skip to content

Commit

Permalink
Fixes #36298 - only show progressbar if option --progress is set
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 21, 2019
1 parent c75fecf commit ad3e731
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/issue-36298
@@ -0,0 +1,6 @@
Bugfix: occ system:cron only shows progess bar if option is set

occ system:cron will only output the progess bar if the newly introduced option --progress is set.
When being executed from crontab occ system::cron shall only print out in case of error.

https://github.com/owncloud/core/issues/36298
18 changes: 13 additions & 5 deletions core/Command/System/Cron.php
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Cron extends Command {
Expand Down Expand Up @@ -63,7 +64,8 @@ public function __construct(IJobList $jobList,
protected function configure() {
$this
->setName('system:cron')
->setDescription('Execute background jobs as cron');
->setDescription('Execute background jobs as cron')
->addOption('progress', 'p', InputOption::VALUE_NONE, 'shows a progress bar - for use in manual execution. Do not use when executing from crontab');
}

/**
Expand Down Expand Up @@ -100,7 +102,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->config->setAppValue('core', 'backgroundjobs_mode', 'cron');
}

$showProgress = $input->getOption('progress');
$progress = new ProgressBar($output);
$progress->setFormat(" %message%\n %current% [%bar%]");

// We only ask for jobs for 14 minutes, because after 15 minutes the next
// system cron task should spawn.
Expand All @@ -112,9 +116,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->jobList->unlockJob($job);
break;
}
$progress->advance();
$jobName = \get_class($job);
$progress->setMessage("Executing: {$job->getId()} - {$jobName}");
if ($showProgress) {
$progress->advance();
$jobName = \get_class($job);
$progress->setMessage("Executing: {$job->getId()} - {$jobName}");
}

$job->execute($this->jobList, $this->logger);

Expand All @@ -134,7 +140,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
if ($this->config->getSystemValue('cron_log', true)) {
$this->config->setAppValue('core', 'lastcron', \time());
}
$output->writeln('');
if ($showProgress) {
$output->writeln('');
}

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/System/CronTest.php
Expand Up @@ -111,7 +111,7 @@ public function testCronRun() {
$this->jobList->method('getNext')->willReturnOnConsecutiveCalls($job, null);
$this->jobList->expects(self::once())->method('setLastJob')->with($job);

$this->commandTester->execute([]);
$this->commandTester->execute(['--progress' => true]);
$output = $this->commandTester->getDisplay();
$this->assertContains('1 [->--------------------------]', $output);
}
Expand Down

0 comments on commit ad3e731

Please sign in to comment.