From 408dcbc263150b3ca2c9204904ebc8ca63876eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 14 Oct 2024 13:06:08 +0000 Subject: [PATCH] Add async exec doc test --- app/controllers/general.php | 2 +- src/Appwrite/Event/Func.php | 2 ++ src/Appwrite/Platform/Workers/Functions.php | 2 +- .../Services/Functions/FunctionsCustomServerTest.php | 11 +++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 03776144e6..b2a07f06f6 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -369,7 +369,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo ; $queueForFunctions - ->setType('delayed_execution_write') + ->setType(Func::TYPE_ASYNC_WRITE) ->setExecution($execution) ->setProject($project) ->trigger(); diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 0cbaf17b60..4dad5802f7 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -8,6 +8,8 @@ use Utopia\Queue\Connection; class Func extends Event { + public const TYPE_ASYNC_WRITE = 'async_write'; + protected string $jwt = ''; protected string $type = ''; protected string $body = ''; diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index aa88f5cfce..7e548f57be 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -74,7 +74,7 @@ class Functions extends Action $type = $payload['type'] ?? ''; // Short-term solution to offhand write operation from API contianer - if ($type === 'delayed_execution_write') { + if ($type === Func::TYPE_ASYNC_WRITE) { $execution = new Document($payload['execution'] ?? []); $execution = $dbForProject->createDocument('executions', $execution); return; diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 59a3041a3f..9b9f03a100 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1675,6 +1675,17 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals($cookie, $response['body']); + // Async execution document creation + $this->assertEventually(function () use ($functionId) { + $executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $executions['headers']['status-code']); + $this->assertEquals(1, count($executions['body']['executions'])); + }); + // Await Aggregation sleep(System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', 30));