mirror of
https://github.com/nextcloud/server.git
synced 2025-03-16 17:24:10 +00:00
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>
This commit is contained in:
parent
b34edf2224
commit
dbab2a825d
3 changed files with 18 additions and 13 deletions
lib
|
@ -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(),
|
||||
|
|
|
@ -43,9 +43,14 @@ 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) {
|
||||
|
|
|
@ -38,12 +38,12 @@ interface IManager {
|
|||
public function getProviders(): array;
|
||||
|
||||
/**
|
||||
* @param string $taskType
|
||||
* @param string $taskTypeId
|
||||
* @return IProvider
|
||||
* @throws Exception
|
||||
* @since 30.0.0
|
||||
*/
|
||||
public function getPreferredProvider(string $taskType);
|
||||
public function getPreferredProvider(string $taskTypeId);
|
||||
|
||||
/**
|
||||
* @return array<array-key,array{name: string, description: string, inputShape: ShapeDescriptor[], inputShapeEnumValues: ShapeEnumValue[][], inputShapeDefaults: array<array-key, numeric|string>, optionalInputShape: ShapeDescriptor[], optionalInputShapeEnumValues: ShapeEnumValue[][], optionalInputShapeDefaults: array<array-key, numeric|string>, outputShape: ShapeDescriptor[], outputShapeEnumValues: ShapeEnumValue[][], optionalOutputShape: ShapeDescriptor[], optionalOutputShapeEnumValues: ShapeEnumValue[][]}>
|
||||
|
|
Loading…
Reference in a new issue