Parcourir la source

fix(bg-jobs): review adjustments

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Julien Veyssier il y a 1 mois
Parent
commit
d967151f52

+ 2 - 6
core/Command/Background/JobBase.php

@@ -32,16 +32,12 @@ use Psr\Log\LoggerInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 abstract class JobBase extends \OC\Core\Command\Base {
-	protected IJobList $jobList;
-	protected LoggerInterface $logger;
 
 	public function __construct(
-		IJobList $jobList,
-		LoggerInterface $logger
+		protected IJobList $jobList,
+		protected LoggerInterface $logger
 	) {
 		parent::__construct();
-		$this->jobList = $jobList;
-		$this->logger = $logger;
 	}
 
 	protected function printJobInfo(int $jobId, IJob $job, OutputInterface $output): void {

+ 21 - 4
core/Command/Background/JobWorker.php

@@ -26,13 +26,25 @@ declare(strict_types=1);
 namespace OC\Core\Command\Background;
 
 use OC\Core\Command\InterruptedException;
+use OC\Files\SetupManager;
+use OCP\BackgroundJob\IJobList;
 use OCP\ITempManager;
+use Psr\Log\LoggerInterface;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class JobWorker extends JobBase {
+
+	public function __construct(
+		protected IJobList $jobList,
+		protected LoggerInterface $logger,
+		private ITempManager $tempManager,
+		private SetupManager $setupManager,
+	) {
+		parent::__construct($jobList, $logger);
+	}
 	protected function configure(): void {
 		parent::configure();
 
@@ -103,7 +115,11 @@ class JobWorker extends JobBase {
 			$job = $this->jobList->getNext(false, $jobClasses);
 			if (!$job) {
 				if ($input->getOption('once') === true) {
-					$output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
+					if ($jobClassesString === null) {
+						$output->writeln('No job is currently queued', OutputInterface::VERBOSITY_VERBOSE);
+					} else {
+						$output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
+					}
 					$output->writeln('Exiting...', OutputInterface::VERBOSITY_VERBOSE);
 					break;
 				}
@@ -120,13 +136,14 @@ class JobWorker extends JobBase {
 				$this->printJobInfo($job->getId(), $job, $output);
 			}
 
-			$job->start($this->jobList);
+			/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */
+			$job->execute($this->jobList);
 
 			$output->writeln('Job ' . $job->getId() . ' has finished', OutputInterface::VERBOSITY_VERBOSE);
 
 			// clean up after unclean jobs
-			\OC_Util::tearDownFS();
-			\OC::$server->get(ITempManager::class)->clean();
+			$this->setupManager->tearDown();
+			$this->tempManager->clean();
 
 			$this->jobList->setLastJob($job);
 			$this->jobList->unlockJob($job);

+ 0 - 2
core/register_command.php

@@ -80,8 +80,6 @@ if ($config->getSystemValueBool('installed', false)) {
 	$application->add(Server::get(Command\TwoFactorAuth\Enable::class));
 	$application->add(Server::get(Command\TwoFactorAuth\Disable::class));
 	$application->add(Server::get(Command\TwoFactorAuth\State::class));
-	$application->add(Server::get(Command\TwoFactorAuth\State::class));
-
 
 	$application->add(Server::get(Command\Background\Cron::class));
 	$application->add(Server::get(Command\Background\WebCron::class));

+ 1 - 2
lib/private/BackgroundJob/JobList.php

@@ -211,8 +211,7 @@ class JobList implements IJobList {
 	}
 
 	/**
-	 * Get the next job in the list
-	 * @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.
+	 * @inheritDoc
 	 */
 	public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob {
 		$query = $this->connection->getQueryBuilder();

+ 4 - 4
lib/public/BackgroundJob/IJobList.php

@@ -108,11 +108,11 @@ interface IJobList {
 	public function getJobsIterator($job, ?int $limit, int $offset): iterable;
 
 	/**
-	 * get the next job in the list
+	 * Get the next job in the list
 	 *
 	 * @param bool $onlyTimeSensitive Whether we get only time sensitive jobs or not
-	 * @param array|null $jobClasses List of job classes to restrict which next job we get
-	 * @return IJob|null
+	 * @param class-string<IJob>[]|null $jobClasses List of job classes to restrict which next job we get
+	 * @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.
 	 * @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added; In 30.0.0 parameter $jobClasses got added
 	 */
 	public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = null): ?IJob;
@@ -176,7 +176,7 @@ interface IJobList {
 	 * Returns a count of jobs per Job class
 	 *
 	 * @return list<array{class:class-string, count:int}>
-	 * @since 29.0.0
+	 * @since 30.0.0
 	 */
 	public function countByClass(): array;
 }