Skip to content

Commit 73247ee

Browse files
committed
feat(task-streaming): add new provider interface
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 3fd4d47 commit 73247ee

6 files changed

Lines changed: 62 additions & 11 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,14 @@
933933
'OCP\\TaskProcessing\\IInternalTaskType' => $baseDir . '/lib/public/TaskProcessing/IInternalTaskType.php',
934934
'OCP\\TaskProcessing\\IManager' => $baseDir . '/lib/public/TaskProcessing/IManager.php',
935935
'OCP\\TaskProcessing\\IProvider' => $baseDir . '/lib/public/TaskProcessing/IProvider.php',
936+
'OCP\\TaskProcessing\\ISynchronousOptionsProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousOptionsProvider.php',
936937
'OCP\\TaskProcessing\\ISynchronousProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousProvider.php',
937938
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
938939
'OCP\\TaskProcessing\\ITaskType' => $baseDir . '/lib/public/TaskProcessing/ITaskType.php',
939940
'OCP\\TaskProcessing\\ITriggerableProvider' => $baseDir . '/lib/public/TaskProcessing/ITriggerableProvider.php',
940941
'OCP\\TaskProcessing\\ShapeDescriptor' => $baseDir . '/lib/public/TaskProcessing/ShapeDescriptor.php',
941942
'OCP\\TaskProcessing\\ShapeEnumValue' => $baseDir . '/lib/public/TaskProcessing/ShapeEnumValue.php',
943+
'OCP\\TaskProcessing\\SynchronousProviderOptions' => $baseDir . '/lib/public/TaskProcessing/SynchronousProviderOptions.php',
942944
'OCP\\TaskProcessing\\Task' => $baseDir . '/lib/public/TaskProcessing/Task.php',
943945
'OCP\\TaskProcessing\\TaskTypes\\AnalyzeImages' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/AnalyzeImages.php',
944946
'OCP\\TaskProcessing\\TaskTypes\\AudioToAudioChat' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/AudioToAudioChat.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,14 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
974974
'OCP\\TaskProcessing\\IInternalTaskType' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IInternalTaskType.php',
975975
'OCP\\TaskProcessing\\IManager' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IManager.php',
976976
'OCP\\TaskProcessing\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IProvider.php',
977+
'OCP\\TaskProcessing\\ISynchronousOptionsProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousOptionsProvider.php',
977978
'OCP\\TaskProcessing\\ISynchronousProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousProvider.php',
978979
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
979980
'OCP\\TaskProcessing\\ITaskType' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITaskType.php',
980981
'OCP\\TaskProcessing\\ITriggerableProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITriggerableProvider.php',
981982
'OCP\\TaskProcessing\\ShapeDescriptor' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ShapeDescriptor.php',
982983
'OCP\\TaskProcessing\\ShapeEnumValue' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ShapeEnumValue.php',
984+
'OCP\\TaskProcessing\\SynchronousProviderOptions' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/SynchronousProviderOptions.php',
983985
'OCP\\TaskProcessing\\Task' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/Task.php',
984986
'OCP\\TaskProcessing\\TaskTypes\\AnalyzeImages' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/AnalyzeImages.php',
985987
'OCP\\TaskProcessing\\TaskTypes\\AudioToAudioChat' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/AudioToAudioChat.php',

lib/private/TaskProcessing/Manager.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959
use OCP\TaskProcessing\IInternalTaskType;
6060
use OCP\TaskProcessing\IManager;
6161
use OCP\TaskProcessing\IProvider;
62-
use OCP\TaskProcessing\ISynchronousProgressiveProvider;
62+
use OCP\TaskProcessing\ISynchronousOptionsProvider;
6363
use OCP\TaskProcessing\ISynchronousProvider;
6464
use OCP\TaskProcessing\ISynchronousWatermarkingProvider;
6565
use OCP\TaskProcessing\ITaskType;
6666
use OCP\TaskProcessing\ITriggerableProvider;
6767
use OCP\TaskProcessing\ShapeDescriptor;
6868
use OCP\TaskProcessing\ShapeEnumValue;
69+
use OCP\TaskProcessing\SynchronousProviderOptions;
6970
use OCP\TaskProcessing\Task;
7071
use OCP\TaskProcessing\TaskTypes\AnalyzeImages;
7172
use OCP\TaskProcessing\TaskTypes\AudioToAudioChat;
@@ -1136,13 +1137,17 @@ public function processTask(Task $task, ISynchronousProvider $provider): bool {
11361137
$this->setTaskStatus($task, Task::STATUS_RUNNING);
11371138
if ($provider instanceof ISynchronousWatermarkingProvider) {
11381139
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress), $task->getIncludeWatermark());
1139-
} elseif ($provider instanceof ISynchronousProgressiveProvider) {
1140+
} elseif ($provider instanceof ISynchronousOptionsProvider) {
1141+
$options = new SynchronousProviderOptions(
1142+
$task->getIncludeWatermark(),
1143+
$task->getPreferStreaming(),
1144+
fn (array $output) => $this->setTaskIntermediateOutput($task->getId(), $output),
1145+
);
11401146
$output = $provider->process(
11411147
$task->getUserId(),
11421148
$input,
11431149
fn (float $progress) => $this->setTaskProgress($task->getId(), $progress),
1144-
fn (array $output) => $this->setTaskIntermediateOutput($task->getId(), $output),
1145-
$task->getPreferStreaming()
1150+
$options,
11461151
);
11471152
} else {
11481153
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress));

lib/public/TaskProcessing/ISynchronousProgressiveProvider.php renamed to lib/public/TaskProcessing/ISynchronousOptionsProvider.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@
1515

1616
/**
1717
* This is the interface that is implemented by apps that
18-
* implement a task processing provider that supports updating the output during processing
19-
* @since 34.0.0
18+
* implement a task processing provider
19+
* @since 35.0.0
2020
*/
21-
interface ISynchronousProgressiveProvider extends ISynchronousProvider {
21+
interface ISynchronousOptionsProvider extends ISynchronousProvider {
2222

2323
/**
2424
* Returns the shape of optional output parameters
2525
*
2626
* @param null|string $userId The user that created the current task
2727
* @param array<string, list<numeric|string|File>|numeric|string|File> $input The task input
2828
* @param callable(float):bool $reportProgress Report the task progress. If this returns false, that means the task was cancelled and processing should be stopped.
29-
* @param null|callable(array):bool $reportOutput Set the task intermediate output
30-
* @param bool $preferStreaming Whether to prefer streaming output or not
29+
* @param SynchronousProviderOptions $options The task options
3130
* @psalm-return array<string, list<numeric|string>|numeric|string>
3231
* @throws ProcessingException
3332
* @since 35.0.0
3433
*/
35-
#[\Override]
36-
public function process(?string $userId, array $input, callable $reportProgress, ?callable $reportOutput = null, bool $preferStreaming = true): array;
34+
public function process(
35+
?string $userId,
36+
array $input,
37+
callable $reportProgress,
38+
SynchronousProviderOptions $options = new SynchronousProviderOptions(),
39+
): array;
3740
}

lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* This is the interface that is implemented by apps that
1818
* implement a task processing provider that supports watermarking
1919
* @since 33.0.0
20+
* @deprecated 35.0.0 Use ISynchronousOptionsProvider instead
2021
*/
2122
interface ISynchronousWatermarkingProvider extends ISynchronousProvider {
2223

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCP\TaskProcessing;
8+
9+
/**
10+
* @since 35.0.0
11+
*/
12+
class SynchronousProviderOptions {
13+
private \Closure $reportOutput;
14+
15+
public function __construct(
16+
private readonly bool $includeWatermarks = false,
17+
private readonly bool $preferStreaming = true,
18+
?callable $reportOutput = null,
19+
) {
20+
$this->reportOutput = $reportOutput !== null
21+
? \Closure::fromCallable($reportOutput)
22+
: static function (array $output): bool {
23+
return true;
24+
};
25+
}
26+
27+
public function getIncludeWatermarks(): bool {
28+
return $this->includeWatermarks;
29+
}
30+
31+
public function getPreferStreaming(): bool {
32+
return $this->preferStreaming;
33+
}
34+
35+
public function getReportOutput(): callable {
36+
return $this->reportOutput;
37+
}
38+
}

0 commit comments

Comments
 (0)