Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(taskprocessing): add manager method to get the list of available…
… task type IDs

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc authored and backportbot[bot] committed Sep 5, 2025
commit 856bb1e16266e7fdf245f1f4714bbe2501d9d810
51 changes: 49 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Manager implements IManager {

public const MAX_TASK_AGE_SECONDS = 60 * 60 * 24 * 30 * 4; // 4 months

private const TASK_TYPES_CACHE_KEY = 'available_task_types_v2';
private const TASK_TYPE_IDS_CACHE_KEY = 'available_task_type_ids';

/** @var list<IProvider>|null */
private ?array $providers = null;

Expand All @@ -89,6 +92,9 @@ class Manager implements IManager {
*/
private ?array $availableTaskTypes = null;

/** @var list<string>|null */
private ?array $availableTaskTypeIds = null;

private IAppData $appData;
private ?array $preferences = null;
private ?array $providersById = null;
Expand Down Expand Up @@ -834,7 +840,7 @@ public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userI
return [];
}
if ($this->availableTaskTypes === null) {
$cachedValue = $this->distributedCache->get('available_task_types_v2');
$cachedValue = $this->distributedCache->get(self::TASK_TYPES_CACHE_KEY);
if ($cachedValue !== null) {
$this->availableTaskTypes = unserialize($cachedValue);
}
Expand Down Expand Up @@ -880,12 +886,53 @@ public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userI
}

$this->availableTaskTypes = $availableTaskTypes;
$this->distributedCache->set('available_task_types_v2', serialize($this->availableTaskTypes), 60);
$this->distributedCache->set(self::TASK_TYPES_CACHE_KEY, serialize($this->availableTaskTypes), 60);
}


return $this->availableTaskTypes;
}
public function getAvailableTaskTypeIds(bool $showDisabled = false, ?string $userId = null): array {
// userId will be obtained from the session if left to null
if (!$this->checkGuestAccess($userId)) {
return [];
}
if ($this->availableTaskTypeIds === null) {
$cachedValue = $this->distributedCache->get(self::TASK_TYPE_IDS_CACHE_KEY);
if ($cachedValue !== null) {
$this->availableTaskTypeIds = $cachedValue;
}
}
// Either we have no cache or showDisabled is turned on, which we don't want to cache, ever.
if ($this->availableTaskTypeIds === null || $showDisabled) {
$taskTypes = $this->_getTaskTypes();
$taskTypeSettings = $this->_getTaskTypeSettings();

$availableTaskTypeIds = [];
foreach ($taskTypes as $taskType) {
if ((!$showDisabled) && isset($taskTypeSettings[$taskType->getId()]) && !$taskTypeSettings[$taskType->getId()]) {
continue;
}
try {
$provider = $this->getPreferredProvider($taskType->getId());
} catch (\OCP\TaskProcessing\Exception\Exception $e) {
continue;
}
$availableTaskTypeIds[] = $taskType->getId();
}

if ($showDisabled) {
// Do not cache showDisabled, ever.
return $availableTaskTypeIds;
}

$this->availableTaskTypeIds = $availableTaskTypeIds;
$this->distributedCache->set(self::TASK_TYPE_IDS_CACHE_KEY, $this->availableTaskTypeIds, 60);
}


return $this->availableTaskTypeIds;
}

public function canHandleTask(Task $task): bool {
return isset($this->getAvailableTaskTypes()[$task->getTaskTypeId()]);
Expand Down
10 changes: 9 additions & 1 deletion lib/public/TaskProcessing/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getProviders(): array;
public function getPreferredProvider(string $taskTypeId);

/**
* @param bool $showDisabled if false, disabled task types will be filtered
* @param bool $showDisabled if false, disabled task types will be filtered out
* @param ?string $userId to check if the user is a guest. Will be obtained from session if left to default
* @return array<string, 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[][]}>
* @since 30.0.0
Expand All @@ -56,6 +56,14 @@ public function getPreferredProvider(string $taskTypeId);
*/
public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userId = null): array;

/**
* @param bool $showDisabled if false, disabled task types will be filtered out
* @param ?string $userId to check if the user is a guest. Will be obtained from session if left to default
* @return list<string>
* @since 32.0.0
*/
public function getAvailableTaskTypeIds(bool $showDisabled = false, ?string $userId = null): array;

/**
* @param Task $task The task to run
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
Expand Down