Skip to content

Commit d967151

Browse files
committed
fix(bg-jobs): review adjustments
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 1acc57b commit d967151

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

core/Command/Background/JobBase.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@
3232
use Symfony\Component\Console\Output\OutputInterface;
3333

3434
abstract class JobBase extends \OC\Core\Command\Base {
35-
protected IJobList $jobList;
36-
protected LoggerInterface $logger;
3735

3836
public function __construct(
39-
IJobList $jobList,
40-
LoggerInterface $logger
37+
protected IJobList $jobList,
38+
protected LoggerInterface $logger
4139
) {
4240
parent::__construct();
43-
$this->jobList = $jobList;
44-
$this->logger = $logger;
4541
}
4642

4743
protected function printJobInfo(int $jobId, IJob $job, OutputInterface $output): void {

core/Command/Background/JobWorker.php

+21-4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,25 @@
2626
namespace OC\Core\Command\Background;
2727

2828
use OC\Core\Command\InterruptedException;
29+
use OC\Files\SetupManager;
30+
use OCP\BackgroundJob\IJobList;
2931
use OCP\ITempManager;
32+
use Psr\Log\LoggerInterface;
3033
use Symfony\Component\Console\Input\InputArgument;
3134
use Symfony\Component\Console\Input\InputInterface;
3235
use Symfony\Component\Console\Input\InputOption;
3336
use Symfony\Component\Console\Output\OutputInterface;
3437

3538
class JobWorker extends JobBase {
39+
40+
public function __construct(
41+
protected IJobList $jobList,
42+
protected LoggerInterface $logger,
43+
private ITempManager $tempManager,
44+
private SetupManager $setupManager,
45+
) {
46+
parent::__construct($jobList, $logger);
47+
}
3648
protected function configure(): void {
3749
parent::configure();
3850

@@ -103,7 +115,11 @@ static function (string $jobClass) {
103115
$job = $this->jobList->getNext(false, $jobClasses);
104116
if (!$job) {
105117
if ($input->getOption('once') === true) {
106-
$output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
118+
if ($jobClassesString === null) {
119+
$output->writeln('No job is currently queued', OutputInterface::VERBOSITY_VERBOSE);
120+
} else {
121+
$output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
122+
}
107123
$output->writeln('Exiting...', OutputInterface::VERBOSITY_VERBOSE);
108124
break;
109125
}
@@ -120,13 +136,14 @@ static function (string $jobClass) {
120136
$this->printJobInfo($job->getId(), $job, $output);
121137
}
122138

123-
$job->start($this->jobList);
139+
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */
140+
$job->execute($this->jobList);
124141

125142
$output->writeln('Job ' . $job->getId() . ' has finished', OutputInterface::VERBOSITY_VERBOSE);
126143

127144
// clean up after unclean jobs
128-
\OC_Util::tearDownFS();
129-
\OC::$server->get(ITempManager::class)->clean();
145+
$this->setupManager->tearDown();
146+
$this->tempManager->clean();
130147

131148
$this->jobList->setLastJob($job);
132149
$this->jobList->unlockJob($job);

core/register_command.php

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@
8080
$application->add(Server::get(Command\TwoFactorAuth\Enable::class));
8181
$application->add(Server::get(Command\TwoFactorAuth\Disable::class));
8282
$application->add(Server::get(Command\TwoFactorAuth\State::class));
83-
$application->add(Server::get(Command\TwoFactorAuth\State::class));
84-
8583

8684
$application->add(Server::get(Command\Background\Cron::class));
8785
$application->add(Server::get(Command\Background\WebCron::class));

lib/private/BackgroundJob/JobList.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): iterable {
211211
}
212212

213213
/**
214-
* Get the next job in the list
215-
* @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob.
214+
* @inheritDoc
216215
*/
217216
public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob {
218217
$query = $this->connection->getQueryBuilder();

lib/public/BackgroundJob/IJobList.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public function getJobs($job, ?int $limit, int $offset): array;
108108
public function getJobsIterator($job, ?int $limit, int $offset): iterable;
109109

110110
/**
111-
* get the next job in the list
111+
* Get the next job in the list
112112
*
113113
* @param bool $onlyTimeSensitive Whether we get only time sensitive jobs or not
114-
* @param array|null $jobClasses List of job classes to restrict which next job we get
115-
* @return IJob|null
114+
* @param class-string<IJob>[]|null $jobClasses List of job classes to restrict which next job we get
115+
* @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob.
116116
* @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added; In 30.0.0 parameter $jobClasses got added
117117
*/
118118
public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob;
@@ -176,7 +176,7 @@ public function hasReservedJob(?string $className): bool;
176176
* Returns a count of jobs per Job class
177177
*
178178
* @return list<array{class:class-string, count:int}>
179-
* @since 29.0.0
179+
* @since 30.0.0
180180
*/
181181
public function countByClass(): array;
182182
}

0 commit comments

Comments
 (0)