Skip to content

Commit 8ea331c

Browse files
committed
fix(task-streaming): fix psalm issues, run cs:fix, gen openapi specs
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 5bfba82 commit 8ea331c

9 files changed

Lines changed: 47 additions & 10 deletions

File tree

core/Controller/TaskProcessingApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ public function setResult(int $taskId, ?array $output = null, ?string $errorMess
647647
* Sets the task intermediate result while it is running
648648
*
649649
* @param int $taskId The id of the task
650-
* @param array<string,mixed>|null $output The intermediate task output, files are represented by their IDs
650+
* @param array<string,mixed> $output The intermediate task output, files are represented by their IDs
651651
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
652652
*
653653
* 200: Result updated successfully

core/Migrations/Version35000Date20260527162338.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
77
* SPDX-License-Identifier: AGPL-3.0-or-later
88
*/
9+
910
namespace OC\Core\Migrations;
1011

1112
use Closure;

core/openapi-ex_app.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,15 +2228,17 @@
22282228
}
22292229
],
22302230
"requestBody": {
2231-
"required": false,
2231+
"required": true,
22322232
"content": {
22332233
"application/json": {
22342234
"schema": {
22352235
"type": "object",
2236+
"required": [
2237+
"output"
2238+
],
22362239
"properties": {
22372240
"output": {
22382241
"type": "object",
2239-
"nullable": true,
22402242
"description": "The intermediate task output, files are represented by their IDs",
22412243
"additionalProperties": {
22422244
"type": "object"

core/openapi-full.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12038,15 +12038,17 @@
1203812038
}
1203912039
],
1204012040
"requestBody": {
12041-
"required": false,
12041+
"required": true,
1204212042
"content": {
1204312043
"application/json": {
1204412044
"schema": {
1204512045
"type": "object",
12046+
"required": [
12047+
"output"
12048+
],
1204612049
"properties": {
1204712050
"output": {
1204812051
"type": "object",
12049-
"nullable": true,
1205012052
"description": "The intermediate task output, files are represented by their IDs",
1205112053
"additionalProperties": {
1205212054
"type": "object"

lib/private/TaskProcessing/Manager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,16 +1227,23 @@ public function setTaskProgress(int $id, float $progress): bool {
12271227
return true;
12281228
}
12291229

1230+
#[\Override]
12301231
public function setTaskIntermediateOutput(int $id, array $output): bool {
12311232
// TODO: Not sure if we should rather catch the exceptions of getTask here and fail silently
12321233
$task = $this->getTask($id);
12331234
if ($task->getStatus() !== Task::STATUS_RUNNING) {
12341235
return false;
12351236
}
12361237
$userId = $task->getUserId();
1237-
if ($userId !== null && $userId !== '' && $this->appManager->isEnabledForAnyone('notify_push')) {
1238+
if ($userId !== null
1239+
&& $userId !== ''
1240+
&& $this->appManager->isEnabledForAnyone('notify_push')
1241+
&& class_exists('\OCA\NotifyPush\Queue\IQueue')
1242+
) {
12381243
try {
1244+
/** @psalm-suppress UndefinedClass */
12391245
$queue = Server::get(\OCA\NotifyPush\Queue\IQueue::class);
1246+
/** @psalm-suppress UndefinedClass */
12401247
$queue->push('notify_custom', [
12411248
'user' => $userId,
12421249
'message' => 'task_' . $task->getId(),

lib/public/TaskProcessing/ISynchronousOptionsProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* SPDX-License-Identifier: AGPL-3.0-or-later
88
*/
99

10-
1110
namespace OCP\TaskProcessing;
1211

1312
use OCP\Files\File;
@@ -31,6 +30,7 @@ interface ISynchronousOptionsProvider extends ISynchronousProvider {
3130
* @throws ProcessingException
3231
* @since 35.0.0
3332
*/
33+
#[\Override]
3434
public function process(
3535
?string $userId,
3636
array $input,

lib/public/TaskProcessing/SynchronousProviderOptions.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-License-Identifier: AGPL-3.0-or-later
66
*/
7+
78
namespace OCP\TaskProcessing;
89

910
/**
@@ -12,6 +13,13 @@
1213
class SynchronousProviderOptions {
1314
private \Closure $reportOutput;
1415

16+
/**
17+
* @param bool $includeWatermarks Whether to include the watermark in the media output files or not
18+
* @param bool $preferStreaming Whether to prefer streaming the output or not
19+
* @param null|callable $reportOutput Callback for the provider to report the intermediate output (streaming)
20+
* @return void
21+
* @since 35.0.0
22+
*/
1523
public function __construct(
1624
private readonly bool $includeWatermarks = false,
1725
private readonly bool $preferStreaming = true,
@@ -24,14 +32,29 @@ public function __construct(
2432
};
2533
}
2634

35+
/**
36+
* Get the includeWatermarks option value
37+
* @return bool Whether to include the watermark in the media output files or not
38+
* @since 35.0.0
39+
*/
2740
public function getIncludeWatermarks(): bool {
2841
return $this->includeWatermarks;
2942
}
3043

44+
/**
45+
* Get the preferStreaming option value
46+
* @return bool Whether to prefer streaming the output or not
47+
* @since 35.0.0
48+
*/
3149
public function getPreferStreaming(): bool {
3250
return $this->preferStreaming;
3351
}
3452

53+
/**
54+
* Get the reportOutput option value
55+
* @return callable Callback for the provider to report the intermediate output (streaming)
56+
* @since 35.0.0
57+
*/
3558
public function getReportOutput(): callable {
3659
return $this->reportOutput;
3760
}

lib/public/TaskProcessing/Task.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ final public function setPreferStreaming(bool $preferStreaming): void {
312312
}
313313

314314
/**
315-
* @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool, includeWatermark: bool, userFacingErrorMessage: ?string}
315+
* @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool, includeWatermark: bool, userFacingErrorMessage: ?string, preferStreaming: bool}
316316
* @since 30.0.0
317317
*/
318318
#[\Override]

openapi.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15746,15 +15746,17 @@
1574615746
}
1574715747
],
1574815748
"requestBody": {
15749-
"required": false,
15749+
"required": true,
1575015750
"content": {
1575115751
"application/json": {
1575215752
"schema": {
1575315753
"type": "object",
15754+
"required": [
15755+
"output"
15756+
],
1575415757
"properties": {
1575515758
"output": {
1575615759
"type": "object",
15757-
"nullable": true,
1575815760
"description": "The intermediate task output, files are represented by their IDs",
1575915761
"additionalProperties": {
1576015762
"type": "object"

0 commit comments

Comments
 (0)