Răsfoiți Sursa

fix(bg-jobs): fix psalm issues

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Marcel Klehr 4 luni în urmă
părinte
comite
352d79deee

+ 7 - 3
core/Command/Background/JobBase.php

@@ -45,6 +45,10 @@ abstract class JobBase extends \OC\Core\Command\Base {
 	protected function printJobInfo(int $jobId, IJob $job, OutputInterface $output): void {
 		$row = $this->jobList->getDetailsById($jobId);
 
+		if ($row === null) {
+			return;
+		}
+
 		$lastRun = new \DateTime();
 		$lastRun->setTimestamp((int) $row['last_run']);
 		$lastChecked = new \DateTime();
@@ -55,10 +59,10 @@ abstract class JobBase extends \OC\Core\Command\Base {
 		$output->writeln('Job class:            ' . get_class($job));
 		$output->writeln('Arguments:            ' . json_encode($job->getArgument()));
 
-		$isTimedJob = $job instanceof \OC\BackgroundJob\TimedJob || $job instanceof \OCP\BackgroundJob\TimedJob;
+		$isTimedJob = $job instanceof \OCP\BackgroundJob\TimedJob;
 		if ($isTimedJob) {
 			$output->writeln('Type:                 timed');
-		} elseif ($job instanceof \OC\BackgroundJob\QueuedJob || $job instanceof \OCP\BackgroundJob\QueuedJob) {
+		} elseif ($job instanceof \OCP\BackgroundJob\QueuedJob) {
 			$output->writeln('Type:                 queued');
 		} else {
 			$output->writeln('Type:                 job');
@@ -81,7 +85,7 @@ abstract class JobBase extends \OC\Core\Command\Base {
 			$interval = $intervalProperty->getValue($job);
 
 			$nextRun = new \DateTime();
-			$nextRun->setTimestamp($row['last_run'] + $interval);
+			$nextRun->setTimestamp((int)$row['last_run'] + $interval);
 
 			if ($nextRun > new \DateTime()) {
 				$output->writeln('Next execution:       <comment>' . $nextRun->format(\DateTimeInterface::ATOM) . '</comment>');

+ 3 - 2
core/Command/Background/JobWorker.php

@@ -27,6 +27,7 @@ namespace OC\Core\Command\Background;
 
 use OC\Core\Command\InterruptedException;
 use OCP\BackgroundJob\IJobList;
+use OCP\ITempManager;
 use Psr\Log\LoggerInterface;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
@@ -101,11 +102,11 @@ class JobWorker extends JobBase {
 				$this->printJobInfo($job->getId(), $job, $output);
 			}
 
-			$job->execute($this->jobList, \OC::$server->getLogger());
+			$job->start($this->jobList);
 
 			// clean up after unclean jobs
 			\OC_Util::tearDownFS();
-			\OC::$server->getTempManager()->clean();
+			\OC::$server->get(ITempManager::class)->clean();
 
 			$this->jobList->setLastJob($job);
 			$this->jobList->unlockJob($job);

+ 0 - 5
core/register_command.php

@@ -55,11 +55,6 @@ use OCP\IConfig;
 use OCP\Server;
 use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand;
 
-use OC\Core\Command;
-use OCP\IConfig;
-use OCP\Server;
-use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand;
-
 $application->add(new CompletionCommand());
 $application->add(Server::get(Command\Status::class));
 $application->add(Server::get(Command\Check::class));

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

@@ -448,11 +448,14 @@ class JobList implements IJobList {
 		$result = $query->executeQuery();
 
 		$jobs = [];
+
 		while (($row = $result->fetch()) !== false) {
+			/**
+			 * @var array{count:int, class:class-string} $row
+			 */
 			$jobs[] = $row;
 		}
 
 		return $jobs;
-
 	}
 }

+ 10 - 2
lib/public/BackgroundJob/IJobList.php

@@ -110,9 +110,9 @@ interface IJobList {
 	/**
 	 * get the next job in the list
 	 *
-	 * @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added
+	 * @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added; In 29.0.0 parameter $jobClass got added
 	 */
-	public function getNext(bool $onlyTimeSensitive = false): ?IJob;
+	public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob;
 
 	/**
 	 * @since 7.0.0
@@ -168,4 +168,12 @@ interface IJobList {
 	 * @since 27.0.0
 	 */
 	public function hasReservedJob(?string $className): bool;
+
+	/**
+	 * Returns a count of jobs per Job class
+	 *
+	 * @return list<array{class:class-string, count:int}>
+	 * @since 29.0.0
+	 */
+	public function countByClass(): array;
 }