diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2024-08-12 13:11:41 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2024-08-12 13:11:41 +0200 |
commit | dbab2a825d4eecf0f16335b149f45859a1c4ba14 (patch) | |
tree | 5c3850bba2bfc80a259deede92e4a591177b346e /lib/private/TaskProcessing/Manager.php | |
parent | b34edf222419df41dac091a4a7b4e41814f5a7c8 (diff) | |
download | nextcloud-server-dbab2a825d4eecf0f16335b149f45859a1c4ba14.tar.gz nextcloud-server-dbab2a825d4eecf0f16335b149f45859a1c4ba14.zip |
fix(taskprocessing): select preferred provider when running sync task, fix task type values according to preferred provider
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib/private/TaskProcessing/Manager.php')
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index a804115a631..37533df088f 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -649,24 +649,24 @@ class Manager implements IManager { return $this->providers; } - public function getPreferredProvider(string $taskType) { + public function getPreferredProvider(string $taskTypeId) { try { $preferences = json_decode($this->config->getAppValue('core', 'ai.taskprocessing_provider_preferences', 'null'), associative: true, flags: JSON_THROW_ON_ERROR); $providers = $this->getProviders(); - if (isset($preferences[$taskType])) { - $provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $preferences[$taskType]))); + if (isset($preferences[$taskTypeId])) { + $provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $preferences[$taskTypeId]))); if ($provider !== false) { return $provider; } } // By default, use the first available provider foreach ($providers as $provider) { - if ($provider->getTaskTypeId() === $taskType) { + if ($provider->getTaskTypeId() === $taskTypeId) { return $provider; } } } catch (\JsonException $e) { - $this->logger->warning('Failed to parse provider preferences while getting preferred provider for task type ' . $taskType, ['exception' => $e]); + $this->logger->warning('Failed to parse provider preferences while getting preferred provider for task type ' . $taskTypeId, ['exception' => $e]); } throw new \OCP\TaskProcessing\Exception\Exception('No matching provider found'); } @@ -674,14 +674,14 @@ class Manager implements IManager { public function getAvailableTaskTypes(): array { if ($this->availableTaskTypes === null) { $taskTypes = $this->_getTaskTypes(); - $providers = $this->getProviders(); $availableTaskTypes = []; - foreach ($providers as $provider) { - if (!isset($taskTypes[$provider->getTaskTypeId()])) { + foreach ($taskTypes as $taskType) { + try { + $provider = $this->getPreferredProvider($taskType->getId()); + } catch (\OCP\TaskProcessing\Exception\Exception $e) { continue; } - $taskType = $taskTypes[$provider->getTaskTypeId()]; try { $availableTaskTypes[$provider->getTaskTypeId()] = [ 'name' => $taskType->getName(), |