aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/TaskProcessing/SynchronousBackgroundJob.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/TaskProcessing/SynchronousBackgroundJob.php')
-rw-r--r--lib/private/TaskProcessing/SynchronousBackgroundJob.php71
1 files changed, 27 insertions, 44 deletions
diff --git a/lib/private/TaskProcessing/SynchronousBackgroundJob.php b/lib/private/TaskProcessing/SynchronousBackgroundJob.php
index 47c3c83a618..19c53d59932 100644
--- a/lib/private/TaskProcessing/SynchronousBackgroundJob.php
+++ b/lib/private/TaskProcessing/SynchronousBackgroundJob.php
@@ -9,15 +9,11 @@ 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\ValidationException;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\ISynchronousProvider;
+use OCP\TaskProcessing\Task;
use Psr\Log\LoggerInterface;
class SynchronousBackgroundJob extends QueuedJob {
@@ -41,57 +37,44 @@ class SynchronousBackgroundJob extends QueuedJob {
if (!$provider instanceof ISynchronousProvider) {
continue;
}
- $taskType = $provider->getTaskTypeId();
+ $taskTypeId = $provider->getTaskTypeId();
+ // only use this provider if it is the preferred one
+ $preferredProvider = $this->taskProcessingManager->getPreferredProvider($taskTypeId);
+ if ($provider->getId() !== $preferredProvider->getId()) {
+ continue;
+ }
try {
- $task = $this->taskProcessingManager->getNextScheduledTask($taskType);
+ $task = $this->taskProcessingManager->getNextScheduledTask([$taskTypeId]);
} catch (NotFoundException $e) {
continue;
} catch (Exception $e) {
$this->logger->error('Unknown error while retrieving scheduled TaskProcessing tasks', ['exception' => $e]);
continue;
}
- try {
- try {
- $input = $this->taskProcessingManager->prepareInputData($task);
- } catch (GenericFileException|NotPermittedException|LockedException|ValidationException $e) {
- $this->logger->warning('Failed to prepare input data for a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);
- $this->taskProcessingManager->setTaskResult($task->getId(), $e->getMessage(), null);
- // Schedule again
- $this->jobList->add(self::class, $argument);
- return;
- }
- try {
- $output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->taskProcessingManager->setTaskProgress($task->getId(), $progress));
- } catch (ProcessingException $e) {
- $this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);
- $this->taskProcessingManager->setTaskResult($task->getId(), $e->getMessage(), null);
- // Schedule again
- $this->jobList->add(self::class, $argument);
- return;
- } catch (\Throwable $e) {
- $this->logger->error('Unknown error while processing TaskProcessing task', ['exception' => $e]);
- $this->taskProcessingManager->setTaskResult($task->getId(), $e->getMessage(), null);
- // Schedule again
- $this->jobList->add(self::class, $argument);
- return;
- }
- $this->taskProcessingManager->setTaskResult($task->getId(), null, $output);
- } catch (NotFoundException $e) {
- $this->logger->info('Could not find task anymore after execution. Moving on.', ['exception' => $e]);
- } catch (Exception $e) {
- $this->logger->error('Failed to report result of TaskProcessing task', ['exception' => $e]);
+ if (!$this->taskProcessingManager->processTask($task, $provider)) {
+ // Schedule again
+ $this->jobList->add(self::class, $argument);
}
}
- $synchronousProviders = array_filter($providers, fn ($provider) =>
- $provider instanceof ISynchronousProvider);
- $taskTypes = array_values(array_map(fn ($provider) =>
- $provider->getTaskTypeId(),
- $synchronousProviders
- ));
+ // 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);
+ $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);
+ $this->taskProcessingManager->getNextScheduledTask([$taskType]);
return true;
} catch (NotFoundException|Exception $e) {
return false;