]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(taskprocessing): fix condition to reschedule SynchronousBackgroundJob 47542/head
authorJulien Veyssier <julien-nc@posteo.net>
Tue, 27 Aug 2024 11:22:12 +0000 (13:22 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 27 Aug 2024 15:55:16 +0000 (15:55 +0000)
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
lib/private/TaskProcessing/SynchronousBackgroundJob.php

index 3d85625da8f4c1ba3f992274b836befb4be8197a..de3b424176c9ec1280dd54d4b4a019d11158c879 100644 (file)
@@ -9,14 +9,8 @@ namespace OC\TaskProcessing;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\BackgroundJob\IJobList;
 use OCP\BackgroundJob\QueuedJob;
-use OCP\Files\GenericFileException;
-use OCP\Files\NotPermittedException;
-use OCP\Lock\LockedException;
 use OCP\TaskProcessing\Exception\Exception;
 use OCP\TaskProcessing\Exception\NotFoundException;
-use OCP\TaskProcessing\Exception\ProcessingException;
-use OCP\TaskProcessing\Exception\UnauthorizedException;
-use OCP\TaskProcessing\Exception\ValidationException;
 use OCP\TaskProcessing\IManager;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\Task;
@@ -63,12 +57,21 @@ class SynchronousBackgroundJob extends QueuedJob {
                        }
                }
 
+               // check if this job needs to be scheduled again:
+               // if there is at least one preferred synchronous provider that has a scheduled task
                $synchronousProviders = array_filter($providers, fn ($provider) =>
                        $provider instanceof ISynchronousProvider);
-               $taskTypes = array_values(array_map(fn ($provider) =>
-                       $provider->getTaskTypeId(),
-                       $synchronousProviders
-               ));
+               $synchronousPreferredProviders = array_filter($synchronousProviders, function ($provider) {
+                       $taskTypeId = $provider->getTaskTypeId();
+                       $preferredProvider = $this->taskProcessingManager->getPreferredProvider($taskTypeId);
+                       return $provider->getId() === $preferredProvider->getId();
+               });
+               $taskTypes = array_values(
+                       array_map(
+                               fn ($provider) => $provider->getTaskTypeId(),
+                               $synchronousPreferredProviders
+                       )
+               );
                $taskTypesWithTasks = array_filter($taskTypes, function ($taskType) {
                        try {
                                $this->taskProcessingManager->getNextScheduledTask([$taskType]);