aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2024-07-17 12:35:13 +0200
committerJulien Veyssier <julien-nc@posteo.net>2024-07-22 11:34:29 +0200
commitfffc7847693080318b759bfa0c0a683325b536b5 (patch)
treeba32ce212a605100dddaffb3a93d4b8690b7ac50 /core
parentfadef0c7ba8e6e6c52a54c0e0c5c27949b165183 (diff)
downloadnextcloud-server-fffc7847693080318b759bfa0c0a683325b536b5.tar.gz
nextcloud-server-fffc7847693080318b759bfa0c0a683325b536b5.zip
feat(taskprocessing): add support for webhooks (http or AppAPI) in the task processing API
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'core')
-rw-r--r--core/Controller/TaskProcessingApiController.php10
-rw-r--r--core/Migrations/Version30000Date20240717111406.php51
-rw-r--r--core/openapi-full.json10
-rw-r--r--core/openapi.json10
4 files changed, 79 insertions, 2 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php
index d9bcbd5da45..6e2a039606f 100644
--- a/core/Controller/TaskProcessingApiController.php
+++ b/core/Controller/TaskProcessingApiController.php
@@ -97,7 +97,8 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
* @param string $type Type of the task
* @param string $appId ID of the app that will execute the task
* @param string $customId An arbitrary identifier for the task
- *
+ * @param string|null $webhookUri URI to be requested when the task finishes
+ * @param string|null $webhookMethod Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED|Http::STATUS_UNAUTHORIZED, array{message: string}, array{}>
*
* 200: Task scheduled successfully
@@ -109,8 +110,13 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
#[UserRateLimit(limit: 20, period: 120)]
#[AnonRateLimit(limit: 5, period: 120)]
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/taskprocessing')]
- public function schedule(array $input, string $type, string $appId, string $customId = ''): DataResponse {
+ public function schedule(
+ array $input, string $type, string $appId, string $customId = '',
+ ?string $webhookUri = null, ?string $webhookMethod = null
+ ): DataResponse {
$task = new Task($type, $input, $appId, $this->userId, $customId);
+ $task->setWebhookUri($webhookUri);
+ $task->setWebhookMethod($webhookMethod);
try {
$this->taskProcessingManager->scheduleTask($task);
diff --git a/core/Migrations/Version30000Date20240717111406.php b/core/Migrations/Version30000Date20240717111406.php
new file mode 100644
index 00000000000..67293d8c1e7
--- /dev/null
+++ b/core/Migrations/Version30000Date20240717111406.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Core\Migrations;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\Types;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ *
+ */
+class Version30000Date20240717111406 extends SimpleMigrationStep {
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ if ($schema->hasTable('taskprocessing_tasks')) {
+ $table = $schema->getTable('taskprocessing_tasks');
+
+ $table->addColumn('webhook_uri', Types::STRING, [
+ 'notnull' => false,
+ 'default' => null,
+ 'length' => 4000,
+ ]);
+ $table->addColumn('webhook_method', Types::STRING, [
+ 'notnull' => false,
+ 'default' => null,
+ 'length' => 64,
+ ]);
+
+ return $schema;
+ }
+
+ return null;
+ }
+}
diff --git a/core/openapi-full.json b/core/openapi-full.json
index 290dc462cdc..a90cc1efaaf 100644
--- a/core/openapi-full.json
+++ b/core/openapi-full.json
@@ -3842,6 +3842,16 @@
"type": "string",
"default": "",
"description": "An arbitrary identifier for the task"
+ },
+ "webhookUri": {
+ "type": "string",
+ "nullable": true,
+ "description": "URI to be requested when the task finishes"
+ },
+ "webhookMethod": {
+ "type": "string",
+ "nullable": true,
+ "description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
}
}
}
diff --git a/core/openapi.json b/core/openapi.json
index 51698f6d430..869bc4ef2c5 100644
--- a/core/openapi.json
+++ b/core/openapi.json
@@ -3842,6 +3842,16 @@
"type": "string",
"default": "",
"description": "An arbitrary identifier for the task"
+ },
+ "webhookUri": {
+ "type": "string",
+ "nullable": true,
+ "description": "URI to be requested when the task finishes"
+ },
+ "webhookMethod": {
+ "type": "string",
+ "nullable": true,
+ "description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
}
}
}