Skip to content

Commit

Permalink
Adjust namespace and print a message when the job was skipped
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 8, 2021
1 parent 8d6e693 commit 340cfac
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions core/Command/Background/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(IJobList $jobList,

protected function configure(): void {
$this
->setName('background:job')
->setName('background-job:execute')
->setDescription('Execute a single background job manually')
->addArgument(
'job-id',
Expand All @@ -75,22 +75,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$this->printJobInfo($jobId, $job, $output);
$output->writeln('');

$lastRun = $job->getLastRun();
if ($input->getOption('force-execute')) {
$output->writeln('');
$lastRun = 0;
$output->writeln('<comment>Forcing execution of the job</comment>');
$output->writeln('');

$this->jobList->resetBackgroundJob($job);
$job = $this->jobList->getById($jobId);
$job->execute($this->jobList, $this->logger);
$this->jobList->setLastJob($job);
}

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

if ($lastRun !== $job->getLastRun()) {
$output->writeln('<info>Job executed!</info>');
$output->writeln('');

if ($job instanceof \OC\BackgroundJob\TimedJob || $job instanceof \OCP\BackgroundJob\TimedJob) {
$this->printJobInfo($jobId, $job, $output);
}
} else {
$output->writeln('<comment>Job was not executed because it is not due</comment>');
$output->writeln('Specify the <question>--force-execute</question> option to run it anyway');
}

return 0;
Expand Down

0 comments on commit 340cfac

Please sign in to comment.