From ed3d598f2e6e7f75648130b673d893c4dcbf8110 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 18 Feb 2024 18:01:25 +0530 Subject: [PATCH 01/31] Added cancel build endpoint --- app/controllers/api/functions.php | 49 ++++++++++++++++++++++++ src/Appwrite/Platform/Workers/Builds.php | 5 +++ 2 files changed, 54 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d3913d180d..75ed72c524 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1475,6 +1475,55 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->noContent(); }); +App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') + ->groups(['api', 'functions']) + ->desc('Cancel build') + ->label('scope', 'functions.write') + ->label('audits.event', 'deployment.update') + ->label('audits.resource', 'function/{request.functionId}') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'functions') + ->label('sdk.method', 'cancelBuild') + ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) + ->label('sdk.response.model', Response::MODEL_NONE) + ->param('functionId', '', new UID(), 'Function ID.') + ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->param('buildId', '', new UID(), 'Build unique ID.') + ->inject('response') + ->inject('dbForProject') + ->inject('project') + ->inject('queueForEvents') + ->action(function (string $functionId, string $deploymentId, string $buildId, Response $response, Database $dbForProject, Document $project, Event $queueForEvents) { + $function = $dbForProject->getDocument('functions', $functionId); + + if ($function->isEmpty()) { + throw new Exception(Exception::FUNCTION_NOT_FOUND); + } + + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + + if ($deployment->isEmpty()) { + throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); + } + + $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $buildId)); + + if ($build->isEmpty()) { + throw new Exception(Exception::BUILD_NOT_FOUND); + } + + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); + $deleteBuild = $executor->deleteRuntime($project->getId(), $deploymentId . "-build"); + + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); + + $queueForEvents + ->setParam('functionId', $function->getId()) + ->setParam('deploymentId', $deployment->getId()); + + $response->noContent(); + }); + App::post('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('Create execution') diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 120a514fc4..9dbcf15371 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -390,6 +390,9 @@ class Builds extends Action $response = null; $err = null; + if ($build->getAttribute('status') === 'cancelled') + return; + Co::join([ Co\go(function () use ($executor, &$response, $project, $deployment, $source, $function, $runtime, $vars, $command, &$err) { try { @@ -456,6 +459,8 @@ class Builds extends Action ]); if ($err) { + if ($build->getAttribute('status') === 'cancelled') + return; throw $err; } From 6ebca949c0bd86442a826cd272b7ad197b3068a2 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 18 Feb 2024 18:04:16 +0530 Subject: [PATCH 02/31] Fixed composer error --- src/Appwrite/Platform/Workers/Builds.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 9dbcf15371..b45d27a940 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -390,8 +390,9 @@ class Builds extends Action $response = null; $err = null; - if ($build->getAttribute('status') === 'cancelled') + if ($build->getAttribute('status') === 'cancelled') { return; + } Co::join([ Co\go(function () use ($executor, &$response, $project, $deployment, $source, $function, $runtime, $vars, $command, &$err) { @@ -459,8 +460,9 @@ class Builds extends Action ]); if ($err) { - if ($build->getAttribute('status') === 'cancelled') + if ($build->getAttribute('status') === 'cancelled') { return; + } throw $err; } From 12f2e761ef78bc4b6c1153fb72e15872b3ad9a41 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 18 Feb 2024 23:25:57 +0530 Subject: [PATCH 03/31] Updated description and response model --- app/controllers/api/functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f7be859558..2e3aff0867 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1477,15 +1477,16 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) - ->desc('Cancel build') + ->desc('Update build status to cancelled') ->label('scope', 'functions.write') ->label('audits.event', 'deployment.update') ->label('audits.resource', 'function/{request.functionId}') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'cancelBuild') - ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) - ->label('sdk.response.model', Response::MODEL_NONE) + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_BUILD) ->param('functionId', '', new UID(), 'Function ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') ->param('buildId', '', new UID(), 'Build unique ID.') @@ -1521,7 +1522,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId' ->setParam('functionId', $function->getId()) ->setParam('deploymentId', $deployment->getId()); - $response->noContent(); + $response->dynamic($build, Response::MODEL_BUILD); }); App::post('/v1/functions/:functionId/executions') From ada1f2abb7400663c8305289a271154d35dcfba8 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:44:21 +0530 Subject: [PATCH 04/31] Mark cancelled first, then kill container --- app/controllers/api/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 2e3aff0867..1fdfdeecc1 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1513,11 +1513,11 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId' throw new Exception(Exception::BUILD_NOT_FOUND); } + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); $deleteBuild = $executor->deleteRuntime($project->getId(), $deploymentId . "-build"); - $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); - $queueForEvents ->setParam('functionId', $function->getId()) ->setParam('deploymentId', $deployment->getId()); From a02a03e3220a5dc49dccb45ceda231572ef7e441 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sat, 24 Feb 2024 00:13:11 +0530 Subject: [PATCH 05/31] Fetch build document from DB --- src/Appwrite/Platform/Workers/Builds.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index b45d27a940..b2f57dac23 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -210,6 +210,12 @@ class Builds extends Action $stdout = ''; $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); + + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { + return; + } + $exit = Console::execute($gitCloneCommand, '', $stdout, $stderr); if ($exit !== 0) { @@ -390,6 +396,7 @@ class Builds extends Action $response = null; $err = null; + $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { return; } @@ -460,6 +467,7 @@ class Builds extends Action ]); if ($err) { + $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { return; } From 0e3a354f1f95da1e723d2132d5a616641444f1bc Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 25 Feb 2024 19:13:55 +0530 Subject: [PATCH 06/31] Create build document in API instead of worker --- app/config/collections.php | 11 +++++++++ app/controllers/api/functions.php | 23 ++++++++++++++++++ src/Appwrite/Platform/Workers/Builds.php | 31 ++++++------------------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 3bc58eff56..2d5aa5945a 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2590,6 +2590,17 @@ $projectCollections = array_merge([ '$id' => ID::custom('builds'), 'name' => 'Builds', 'attributes' => [ + [ + '$id' => ID::custom('creationTime'), + 'type' => Database::VAR_DATETIME, + 'format' => '', + 'size' => 0, + 'signed' => false, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['datetime'], + ], [ '$id' => ID::custom('startTime'), 'type' => Database::VAR_DATETIME, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 1fdfdeecc1..5b933f6aad 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1184,6 +1184,29 @@ App::post('/v1/functions/:functionId/deployments') $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment->setAttribute('size', $fileSize)->setAttribute('metadata', $metadata)); } + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'creationTime' => DateTime::now(), + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => strtolower($deviceFunctions->getType()), + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + // Start the build $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index b2f57dac23..0bc7b53ab2 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -147,32 +147,15 @@ class Builds extends Action $isNewBuild = empty($buildId); $deviceFunctions = $getFunctionsDevice($project->getId()); - if ($isNewBuild) { - $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => $startTime, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'processing', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => strtolower($deviceFunctions->getType()), - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); - - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - } else { - $build = $dbForProject->getDocument('builds', $buildId); + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { + return; } + $build->setAttribute('status', 'processing'); + $build->setAttribute('startTime', $startTime); + $build = $dbForProject->updateDocument('builds', $buildId, $build); + $source = $deployment->getAttribute('path', ''); $installationId = $deployment->getAttribute('installationId', ''); $providerRepositoryId = $deployment->getAttribute('providerRepositoryId', ''); From 353092ba0045a1e1cfd178758c7011e3ef78802f Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 26 Feb 2024 00:05:00 +0530 Subject: [PATCH 07/31] Remove create build endpoint --- app/config/collections.php | 11 --- app/controllers/api/functions.php | 91 ++++++----------------- app/controllers/api/vcs.php | 22 ++++++ docs/references/functions/create-build.md | 1 - src/Appwrite/Platform/Workers/Builds.php | 1 + 5 files changed, 45 insertions(+), 81 deletions(-) delete mode 100644 docs/references/functions/create-build.md diff --git a/app/config/collections.php b/app/config/collections.php index 2d5aa5945a..3bc58eff56 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2590,17 +2590,6 @@ $projectCollections = array_merge([ '$id' => ID::custom('builds'), 'name' => 'Builds', 'attributes' => [ - [ - '$id' => ID::custom('creationTime'), - 'type' => Database::VAR_DATETIME, - 'format' => '', - 'size' => 0, - 'signed' => false, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => ['datetime'], - ], [ '$id' => ID::custom('startTime'), 'type' => Database::VAR_DATETIME, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5b933f6aad..ad89409968 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -116,6 +116,28 @@ $redeployVcs = function (Request $request, Document $function, Document $project 'activate' => true, ])); + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) @@ -1188,7 +1210,6 @@ App::post('/v1/functions/:functionId/deployments') $build = $dbForProject->createDocument('builds', new Document([ '$id' => $buildId, '$permissions' => [], - 'creationTime' => DateTime::now(), 'startTime' => null, 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), @@ -1430,74 +1451,6 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId') $response->noContent(); }); -App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') - ->groups(['api', 'functions']) - ->desc('Create build') - ->label('scope', 'functions.write') - ->label('event', 'functions.[functionId].deployments.[deploymentId].update') - ->label('audits.event', 'deployment.update') - ->label('audits.resource', 'function/{request.functionId}') - ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) - ->label('sdk.namespace', 'functions') - ->label('sdk.method', 'createBuild') - ->label('sdk.description', '/docs/references/functions/create-build.md') - ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) - ->label('sdk.response.model', Response::MODEL_NONE) - ->param('functionId', '', new UID(), 'Function ID.') - ->param('deploymentId', '', new UID(), 'Deployment ID.') - ->param('buildId', '', new UID(), 'Build unique ID.') - ->inject('request') - ->inject('response') - ->inject('dbForProject') - ->inject('project') - ->inject('queueForEvents') - ->inject('queueForBuilds') - ->action(function (string $functionId, string $deploymentId, string $buildId, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds) { - - $function = $dbForProject->getDocument('functions', $functionId); - - if ($function->isEmpty()) { - throw new Exception(Exception::FUNCTION_NOT_FOUND); - } - - $deployment = $dbForProject->getDocument('deployments', $deploymentId); - - if ($deployment->isEmpty()) { - throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); - } - - $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $buildId)); - - if ($build->isEmpty()) { - throw new Exception(Exception::BUILD_NOT_FOUND); - } - - $deploymentId = ID::unique(); - - $deployment->removeAttribute('$internalId'); - $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$id' => $deploymentId, - 'buildId' => '', - 'buildInternalId' => '', - 'entrypoint' => $function->getAttribute('entrypoint'), - 'commands' => $function->getAttribute('commands', ''), - 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), - ])); - - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment) - ->setProject($project) - ->trigger(); - - $queueForEvents - ->setParam('functionId', $function->getId()) - ->setParam('deploymentId', $deployment->getId()); - - $response->noContent(); - }); - App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) ->desc('Update build status to cancelled') diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 1b0c993e11..58f4cec245 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -234,6 +234,28 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) diff --git a/docs/references/functions/create-build.md b/docs/references/functions/create-build.md deleted file mode 100644 index 31a288a35a..0000000000 --- a/docs/references/functions/create-build.md +++ /dev/null @@ -1 +0,0 @@ -Create a new build for an Appwrite Function deployment. This endpoint can be used to retry a failed build. \ No newline at end of file diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 0bc7b53ab2..866b7fcf5d 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -154,6 +154,7 @@ class Builds extends Action $build->setAttribute('status', 'processing'); $build->setAttribute('startTime', $startTime); + $build->setAttribute('sourceType', strtolower($deviceFunctions->getType())); $build = $dbForProject->updateDocument('builds', $buildId, $build); $source = $deployment->getAttribute('path', ''); From 727fe2c9a91cc20f6b2c0fed27ae20dc44c565f9 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 26 Feb 2024 12:33:54 +0530 Subject: [PATCH 08/31] Update newBuild condition --- src/Appwrite/Platform/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 866b7fcf5d..47adf29d56 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -144,7 +144,6 @@ class Builds extends Action $startTime = DateTime::now(); $durationStart = \microtime(true); $buildId = $deployment->getAttribute('buildId', ''); - $isNewBuild = empty($buildId); $deviceFunctions = $getFunctionsDevice($project->getId()); $build = $dbForProject->getDocument('builds', $buildId); @@ -152,6 +151,7 @@ class Builds extends Action return; } + $isNewBuild = empty($build->getAttribute('startTime')); $build->setAttribute('status', 'processing'); $build->setAttribute('startTime', $startTime); $build->setAttribute('sourceType', strtolower($deviceFunctions->getType())); From 56760b14cb09bbbe717047572a824f825111cf7b Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:37:47 +0530 Subject: [PATCH 09/31] Restore create build endpoint --- app/controllers/api/functions.php | 105 +++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ad89409968..9be94484bc 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1451,7 +1451,94 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId') $response->noContent(); }); -App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') +App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') + ->groups(['api', 'functions']) + ->desc('Create build') + ->label('scope', 'functions.write') + ->label('event', 'functions.[functionId].deployments.[deploymentId].update') + ->label('audits.event', 'deployment.update') + ->label('audits.resource', 'function/{request.functionId}') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'functions') + ->label('sdk.method', 'createBuild') + ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) + ->label('sdk.response.model', Response::MODEL_NONE) + ->param('functionId', '', new UID(), 'Function ID.') + ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->param('buildId', '', new UID(), 'Build unique ID.') + ->inject('request') + ->inject('response') + ->inject('dbForProject') + ->inject('project') + ->inject('queueForEvents') + ->inject('queueForBuilds') + ->action(function (string $functionId, string $deploymentId, string $buildId, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds) { + + $function = $dbForProject->getDocument('functions', $functionId); + + if ($function->isEmpty()) { + throw new Exception(Exception::FUNCTION_NOT_FOUND); + } + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + + if ($deployment->isEmpty()) { + throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); + } + $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $buildId)); + + if ($build->isEmpty()) { + throw new Exception(Exception::BUILD_NOT_FOUND); + } + + $deploymentId = ID::unique(); + + $deployment->removeAttribute('$internalId'); + $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ + '$id' => $deploymentId, + 'buildId' => '', + 'buildInternalId' => '', + 'entrypoint' => $function->getAttribute('entrypoint'), + 'commands' => $function->getAttribute('commands', ''), + 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), + ])); + + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + + $queueForBuilds + ->setType(BUILD_TYPE_DEPLOYMENT) + ->setResource($function) + ->setDeployment($deployment) + ->setProject($project) + ->trigger(); + + $queueForEvents + ->setParam('functionId', $function->getId()) + ->setParam('deploymentId', $deployment->getId()); + + $response->noContent(); + }); + + App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) ->desc('Update build status to cancelled') ->label('scope', 'functions.write') @@ -1501,7 +1588,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId' $response->dynamic($build, Response::MODEL_BUILD); }); -App::post('/v1/functions/:functionId/executions') + App::post('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('Create execution') ->label('scope', 'execution.write') @@ -1792,7 +1879,7 @@ App::post('/v1/functions/:functionId/executions') ->dynamic($execution, Response::MODEL_EXECUTION); }); -App::get('/v1/functions/:functionId/executions') + App::get('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('List executions') ->label('scope', 'execution.read') @@ -1867,7 +1954,7 @@ App::get('/v1/functions/:functionId/executions') ]), Response::MODEL_EXECUTION_LIST); }); -App::get('/v1/functions/:functionId/executions/:executionId') + App::get('/v1/functions/:functionId/executions/:executionId') ->groups(['api', 'functions']) ->desc('Get execution') ->label('scope', 'execution.read') @@ -1916,7 +2003,7 @@ App::get('/v1/functions/:functionId/executions/:executionId') // Variables -App::post('/v1/functions/:functionId/variables') + App::post('/v1/functions/:functionId/variables') ->desc('Create variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') @@ -1980,7 +2067,7 @@ App::post('/v1/functions/:functionId/variables') ->dynamic($variable, Response::MODEL_VARIABLE); }); -App::get('/v1/functions/:functionId/variables') + App::get('/v1/functions/:functionId/variables') ->desc('List variables') ->groups(['api', 'functions']) ->label('scope', 'functions.read') @@ -2007,7 +2094,7 @@ App::get('/v1/functions/:functionId/variables') ]), Response::MODEL_VARIABLE_LIST); }); -App::get('/v1/functions/:functionId/variables/:variableId') + App::get('/v1/functions/:functionId/variables/:variableId') ->desc('Get variable') ->groups(['api', 'functions']) ->label('scope', 'functions.read') @@ -2046,7 +2133,7 @@ App::get('/v1/functions/:functionId/variables/:variableId') $response->dynamic($variable, Response::MODEL_VARIABLE); }); -App::put('/v1/functions/:functionId/variables/:variableId') + App::put('/v1/functions/:functionId/variables/:variableId') ->desc('Update variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') @@ -2107,7 +2194,7 @@ App::put('/v1/functions/:functionId/variables/:variableId') $response->dynamic($variable, Response::MODEL_VARIABLE); }); -App::delete('/v1/functions/:functionId/variables/:variableId') + App::delete('/v1/functions/:functionId/variables/:variableId') ->desc('Delete variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') From 974104f8b06a4f063531a805c34f42c2a97988dc Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:30:06 +0100 Subject: [PATCH 10/31] address PR comments --- app/controllers/api/functions.php | 7 +++---- src/Appwrite/Platform/Workers/Builds.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 9be94484bc..5e8624a91e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1540,7 +1540,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) - ->desc('Update build status to cancelled') + ->desc('Update build status') ->label('scope', 'functions.write') ->label('audits.event', 'deployment.update') ->label('audits.resource', 'function/{request.functionId}') @@ -1552,12 +1552,11 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->label('sdk.response.model', Response::MODEL_BUILD) ->param('functionId', '', new UID(), 'Function ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') - ->param('buildId', '', new UID(), 'Build unique ID.') ->inject('response') ->inject('dbForProject') ->inject('project') ->inject('queueForEvents') - ->action(function (string $functionId, string $deploymentId, string $buildId, Response $response, Database $dbForProject, Document $project, Event $queueForEvents) { + ->action(function (string $functionId, string $deploymentId, Response $response, Database $dbForProject, Document $project, Event $queueForEvents) { $function = $dbForProject->getDocument('functions', $functionId); if ($function->isEmpty()) { @@ -1570,7 +1569,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } - $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $buildId)); + $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''))); if ($build->isEmpty()) { throw new Exception(Exception::BUILD_NOT_FOUND); diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 47adf29d56..4b2b6ef766 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -9,6 +9,7 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; use Exception; +use Appwrite\Extend\Exception as AppwriteException; use Swoole\Coroutine as Co; use Executor\Executor; use Utopia\App; @@ -144,6 +145,10 @@ class Builds extends Action $startTime = DateTime::now(); $durationStart = \microtime(true); $buildId = $deployment->getAttribute('buildId', ''); + if ($buildId->isEmpty()) { + throw new AppwriteException(AppwriteException::BUILD_NOT_FOUND); + } + $deviceFunctions = $getFunctionsDevice($project->getId()); $build = $dbForProject->getDocument('builds', $buildId); @@ -494,6 +499,11 @@ class Builds extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn() => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); } catch (\Throwable $th) { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { + return; + } + $endTime = DateTime::now(); $durationEnd = \microtime(true); $build->setAttribute('endTime', $endTime); From 2b69f0b7e2ee7f2bdd541580a8063d454a0006dd Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:14:37 +0530 Subject: [PATCH 11/31] Fix formatting --- app/controllers/api/functions.php | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index c3f0570529..f68c8327b7 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1524,26 +1524,26 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ])); $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => null, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'waiting', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => '', - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) @@ -1557,7 +1557,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->noContent(); }); - App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') +App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) ->desc('Update build status') ->label('scope', 'functions.write') @@ -1606,7 +1606,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->dynamic($build, Response::MODEL_BUILD); }); - App::post('/v1/functions/:functionId/executions') +App::post('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('Create execution') ->label('scope', 'execution.write') @@ -1897,7 +1897,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->dynamic($execution, Response::MODEL_EXECUTION); }); - App::get('/v1/functions/:functionId/executions') +App::get('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('List executions') ->label('scope', 'execution.read') @@ -1978,7 +1978,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ]), Response::MODEL_EXECUTION_LIST); }); - App::get('/v1/functions/:functionId/executions/:executionId') +App::get('/v1/functions/:functionId/executions/:executionId') ->groups(['api', 'functions']) ->desc('Get execution') ->label('scope', 'execution.read') @@ -2027,7 +2027,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') // Variables - App::post('/v1/functions/:functionId/variables') +App::post('/v1/functions/:functionId/variables') ->desc('Create variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') @@ -2091,7 +2091,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->dynamic($variable, Response::MODEL_VARIABLE); }); - App::get('/v1/functions/:functionId/variables') +App::get('/v1/functions/:functionId/variables') ->desc('List variables') ->groups(['api', 'functions']) ->label('scope', 'functions.read') @@ -2118,7 +2118,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ]), Response::MODEL_VARIABLE_LIST); }); - App::get('/v1/functions/:functionId/variables/:variableId') +App::get('/v1/functions/:functionId/variables/:variableId') ->desc('Get variable') ->groups(['api', 'functions']) ->label('scope', 'functions.read') @@ -2157,7 +2157,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->dynamic($variable, Response::MODEL_VARIABLE); }); - App::put('/v1/functions/:functionId/variables/:variableId') +App::put('/v1/functions/:functionId/variables/:variableId') ->desc('Update variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') @@ -2218,7 +2218,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->dynamic($variable, Response::MODEL_VARIABLE); }); - App::delete('/v1/functions/:functionId/variables/:variableId') +App::delete('/v1/functions/:functionId/variables/:variableId') ->desc('Delete variable') ->groups(['api', 'functions']) ->label('scope', 'functions.write') From 3123bf6b7263f0fa556563bb7eb1df435bb6eff0 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:16:17 +0530 Subject: [PATCH 12/31] Fix formatting --- src/Appwrite/Platform/Workers/Builds.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index a95c8f82e8..e64e69699c 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -335,14 +335,13 @@ class Builds extends Action $deploymentModel = new Deployment(); $deploymentUpdate = $queueForEvents - ->setQueue(Event::WEBHOOK_QUEUE_NAME) - ->setClass(Event::WEBHOOK_CLASS_NAME) - ->setProject($project) - ->setEvent('functions.[functionId].deployments.[deploymentId].update') - ->setParam('functionId', $function->getId()) - ->setParam('deploymentId', $deployment->getId()) - ->setPayload($deployment->getArrayCopy(array_keys($deploymentModel->getRules()))) - ; + ->setQueue(Event::WEBHOOK_QUEUE_NAME) + ->setClass(Event::WEBHOOK_CLASS_NAME) + ->setProject($project) + ->setEvent('functions.[functionId].deployments.[deploymentId].update') + ->setParam('functionId', $function->getId()) + ->setParam('deploymentId', $deployment->getId()) + ->setPayload($deployment->getArrayCopy(array_keys($deploymentModel->getRules()))); $deploymentUpdate->trigger(); @@ -438,8 +437,8 @@ class Builds extends Action $build = $dbForProject->updateDocument('builds', $build->getId(), $build); /** - * Send realtime Event - */ + * Send realtime Event + */ $target = Realtime::fromPayload( // Pass first, most verbose event pattern event: $allEvents[0], From 0dd908b14c6fa5dc35dd0253f848351b4217c639 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:47:29 +0530 Subject: [PATCH 13/31] Fix formatting --- src/Appwrite/Platform/Workers/Builds.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index e64e69699c..2fd2cb0011 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -21,7 +21,6 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Conflict; use Utopia\Database\Exception\Restricted; use Utopia\Database\Exception\Structure; -use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Logger\Log; use Utopia\Platform\Action; From e2b2df1e316d7ecf28f4ea040f4be0dd0bcfd3cb Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:18:36 +0530 Subject: [PATCH 14/31] Fix formatting --- composer.lock | 164 ++++++++++++----------- src/Appwrite/Platform/Workers/Builds.php | 2 +- 2 files changed, 86 insertions(+), 80 deletions(-) diff --git a/composer.lock b/composer.lock index 0358bdc53f..14e0a36d1d 100644 --- a/composer.lock +++ b/composer.lock @@ -156,21 +156,21 @@ }, { "name": "appwrite/php-runtimes", - "version": "0.13.3", + "version": "0.13.5", "source": { "type": "git", "url": "https://github.com/appwrite/runtimes.git", - "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d" + "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/runtimes/zipball/5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", - "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", + "url": "https://api.github.com/repos/appwrite/runtimes/zipball/ba24c3a163f1a1da6cd355db92def508d05e59f7", + "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/system": "0.7.*" + "utopia-php/system": "0.8.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -204,9 +204,9 @@ ], "support": { "issues": "https://github.com/appwrite/runtimes/issues", - "source": "https://github.com/appwrite/runtimes/tree/0.13.3" + "source": "https://github.com/appwrite/runtimes/tree/0.13.5" }, - "time": "2024-03-01T14:47:47+00:00" + "time": "2024-04-01T10:35:02+00:00" }, { "name": "beberlei/assert", @@ -1406,16 +1406,16 @@ }, { "name": "utopia-php/cache", - "version": "0.9.0", + "version": "0.9.1", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e" + "reference": "552b4c554bb14d0c529631ce304cdf4a2b9d06a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", - "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/552b4c554bb14d0c529631ce304cdf4a2b9d06a6", + "reference": "552b4c554bb14d0c529631ce304cdf4a2b9d06a6", "shasum": "" }, "require": { @@ -1450,9 +1450,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.9.0" + "source": "https://github.com/utopia-php/cache/tree/0.9.1" }, - "time": "2024-01-07T18:11:23+00:00" + "time": "2024-03-19T17:07:20+00:00" }, { "name": "utopia-php/cli", @@ -1719,16 +1719,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.3", + "version": "0.33.6", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "893d602cd96676810c25fc9b9a2e9360eebb898f" + "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/893d602cd96676810c25fc9b9a2e9360eebb898f", - "reference": "893d602cd96676810c25fc9b9a2e9360eebb898f", + "url": "https://api.github.com/repos/utopia-php/http/zipball/8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", + "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", "shasum": "" }, "require": { @@ -1758,9 +1758,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.3" + "source": "https://github.com/utopia-php/http/tree/0.33.6" }, - "time": "2024-03-11T13:43:23+00:00" + "time": "2024-03-21T18:10:57+00:00" }, { "name": "utopia-php/image", @@ -2337,16 +2337,16 @@ }, { "name": "utopia-php/storage", - "version": "0.18.3", + "version": "0.18.4", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6" + "reference": "94ab8758fabcefee5c5fa723616e45719833f922" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/faa0279519ac14f3501e8b138e0865ad9d12bff6", - "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/94ab8758fabcefee5c5fa723616e45719833f922", + "reference": "94ab8758fabcefee5c5fa723616e45719833f922", "shasum": "" }, "require": { @@ -2386,9 +2386,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.18.3" + "source": "https://github.com/utopia-php/storage/tree/0.18.4" }, - "time": "2023-12-31T11:45:12+00:00" + "time": "2024-04-02T08:24:09+00:00" }, { "name": "utopia-php/swoole", @@ -2443,16 +2443,16 @@ }, { "name": "utopia-php/system", - "version": "0.7.2", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "4593d4d334b0c15879c4744a826e0362924c5d66" + "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/4593d4d334b0c15879c4744a826e0362924c5d66", - "reference": "4593d4d334b0c15879c4744a826e0362924c5d66", + "url": "https://api.github.com/repos/utopia-php/system/zipball/a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", + "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", "shasum": "" }, "require": { @@ -2493,9 +2493,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.7.2" + "source": "https://github.com/utopia-php/system/tree/0.8.0" }, - "time": "2023-10-20T01:39:17+00:00" + "time": "2024-04-01T10:22:28+00:00" }, { "name": "utopia-php/vcs", @@ -2731,16 +2731,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.37.7", + "version": "0.37.12", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "c9c07e8d96b80f62507bbb5ef90fa0769e560621" + "reference": "882881934e8014b2135590e7ea5f402ab4513c38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/c9c07e8d96b80f62507bbb5ef90fa0769e560621", - "reference": "c9c07e8d96b80f62507bbb5ef90fa0769e560621", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/882881934e8014b2135590e7ea5f402ab4513c38", + "reference": "882881934e8014b2135590e7ea5f402ab4513c38", "shasum": "" }, "require": { @@ -2776,9 +2776,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.37.7" + "source": "https://github.com/appwrite/sdk-generator/tree/0.37.12" }, - "time": "2024-03-09T16:57:18+00:00" + "time": "2024-04-17T19:14:43+00:00" }, { "name": "doctrine/deprecations", @@ -2899,16 +2899,16 @@ }, { "name": "laravel/pint", - "version": "v1.14.0", + "version": "v1.15.2", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e" + "reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/6b127276e3f263f7bb17d5077e9e0269e61b2a0e", - "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e", + "url": "https://api.github.com/repos/laravel/pint/zipball/2c9f8004899815f3f0ee3cb28ef7281e2b589134", + "reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134", "shasum": "" }, "require": { @@ -2919,13 +2919,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.49.0", - "illuminate/view": "^10.43.0", - "larastan/larastan": "^2.8.1", + "friendsofphp/php-cs-fixer": "^3.54.0", + "illuminate/view": "^10.48.8", + "larastan/larastan": "^2.9.5", "laravel-zero/framework": "^10.3.0", - "mockery/mockery": "^1.6.7", + "mockery/mockery": "^1.6.11", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.33.6" + "pestphp/pest": "^2.34.7" }, "bin": [ "builds/pint" @@ -2961,20 +2961,20 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-02-20T17:38:05+00:00" + "time": "2024-04-23T15:42:34+00:00" }, { "name": "matthiasmullie/minify", - "version": "1.3.71", + "version": "1.3.73", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1" + "reference": "cb7a9297b4ab070909cefade30ee95054d4ae87a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", - "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/cb7a9297b4ab070909cefade30ee95054d4ae87a", + "reference": "cb7a9297b4ab070909cefade30ee95054d4ae87a", "shasum": "" }, "require": { @@ -3024,7 +3024,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.71" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.73" }, "funding": [ { @@ -3032,7 +3032,7 @@ "type": "github" } ], - "time": "2023-04-25T20:33:03+00:00" + "time": "2024-03-15T10:27:10+00:00" }, { "name": "matthiasmullie/path-converter", @@ -3377,28 +3377,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", + "version": "5.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/298d2febfe79d03fe714eb871d5538da55205b1a", + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", + "phpdocumentor/type-resolver": "^1.7", + "phpstan/phpdoc-parser": "^1.7", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" + "mockery/mockery": "~1.3.5", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^5.13" }, "type": "library", "extra": { @@ -3422,15 +3429,15 @@ }, { "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "email": "opensource@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.0" }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2024-04-09T21:13:58+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -3561,16 +3568,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.26.0", + "version": "1.28.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "231e3186624c03d7e7c890ec662b81e6b0405227" + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227", - "reference": "231e3186624c03d7e7c890ec662b81e6b0405227", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", "shasum": "" }, "require": { @@ -3602,9 +3609,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" }, - "time": "2024-02-23T16:05:55+00:00" + "time": "2024-04-03T18:51:33+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4880,16 +4887,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -4901,7 +4908,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -4922,8 +4929,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -4931,7 +4937,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", @@ -5470,5 +5476,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 2fd2cb0011..c59dfef01a 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -5,11 +5,11 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Event; use Appwrite\Event\Func; use Appwrite\Event\Usage; +use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; use Exception; -use Appwrite\Extend\Exception as AppwriteException; use Swoole\Coroutine as Co; use Utopia\App; use Utopia\Cache\Cache; From ea9c71757cc415c275e696c1b854606b6e1b2642 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:19:14 +0530 Subject: [PATCH 15/31] Fix tests --- app/controllers/api/functions.php | 2 +- src/Appwrite/Platform/Workers/Builds.php | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f68c8327b7..1bf51a52b6 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1234,7 +1234,7 @@ App::post('/v1/functions/:functionId/deployments') 'path' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => strtolower($deviceFunctions->getType()), + 'sourceType' => strtolower($deviceForFunctions->getType()), 'logs' => '', 'endTime' => null, 'duration' => 0, diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index c59dfef01a..5fcd2f2e24 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -10,6 +10,7 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; use Exception; +use Executor\Executor; use Swoole\Coroutine as Co; use Utopia\App; use Utopia\Cache\Cache; @@ -156,13 +157,11 @@ class Builds extends Action $startTime = DateTime::now(); $durationStart = \microtime(true); $buildId = $deployment->getAttribute('buildId', ''); - if ($buildId->isEmpty()) { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->isEmpty()) { throw new AppwriteException(AppwriteException::BUILD_NOT_FOUND); } - $deviceFunctions = $getFunctionsDevice($project->getId()); - - $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { return; } @@ -170,7 +169,7 @@ class Builds extends Action $isNewBuild = empty($build->getAttribute('startTime')); $build->setAttribute('status', 'processing'); $build->setAttribute('startTime', $startTime); - $build->setAttribute('sourceType', strtolower($deviceFunctions->getType())); + $build->setAttribute('sourceType', strtolower($deviceForFunctions->getType())); $build = $dbForProject->updateDocument('builds', $buildId, $build); $source = $deployment->getAttribute('path', ''); From fba60f974e3efeeaf00eceeee5bf00340dd33bc4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:46:58 +0530 Subject: [PATCH 16/31] Throw exception for cancellation if build is already complete --- app/controllers/api/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 1bf51a52b6..8de0887847 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1594,6 +1594,10 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId' throw new Exception(Exception::BUILD_NOT_FOUND); } + if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Build is already completed and cannot be cancelled.'); + } + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); From b880a0a7b238948adf4ae028f98fefbeecbf3cdb Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 27 May 2024 18:21:28 +0530 Subject: [PATCH 17/31] Remove :buildId from endpoint as discussed --- app/controllers/api/functions.php | 2 +- composer.lock | 138 +++++++++++++----------------- 2 files changed, 60 insertions(+), 80 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ff7eba435a..1e8de09bd3 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1562,7 +1562,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') $response->noContent(); }); -App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') +App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') ->groups(['api', 'functions']) ->desc('Update build status') ->label('scope', 'functions.write') diff --git a/composer.lock b/composer.lock index f4b7876945..5c30d5a1cc 100644 --- a/composer.lock +++ b/composer.lock @@ -822,16 +822,16 @@ }, { "name": "paragonie/constant_time_encoding", - "version": "v2.6.3", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "58c3f47f650c94ec05a151692652a868995d2938" + "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", - "reference": "58c3f47f650c94ec05a151692652a868995d2938", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/52a0d99e69f56b9ec27ace92ba56897fe6993105", + "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105", "shasum": "" }, "require": { @@ -885,7 +885,7 @@ "issues": "https://github.com/paragonie/constant_time_encoding/issues", "source": "https://github.com/paragonie/constant_time_encoding" }, - "time": "2022-06-14T06:56:20+00:00" + "time": "2024-05-08T12:18:48+00:00" }, { "name": "phpmailer/phpmailer", @@ -1672,16 +1672,16 @@ }, { "name": "utopia-php/dsn", - "version": "0.2.0", + "version": "0.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/dsn.git", - "reference": "c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7" + "reference": "42ee37a3d1785100b2f69091c9d4affadb6846eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/dsn/zipball/c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7", - "reference": "c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7", + "url": "https://api.github.com/repos/utopia-php/dsn/zipball/42ee37a3d1785100b2f69091c9d4affadb6846eb", + "reference": "42ee37a3d1785100b2f69091c9d4affadb6846eb", "shasum": "" }, "require": { @@ -1713,9 +1713,9 @@ ], "support": { "issues": "https://github.com/utopia-php/dsn/issues", - "source": "https://github.com/utopia-php/dsn/tree/0.2.0" + "source": "https://github.com/utopia-php/dsn/tree/0.2.1" }, - "time": "2023-11-02T12:01:43+00:00" + "time": "2024-05-07T02:01:25+00:00" }, { "name": "utopia-php/framework", @@ -1966,22 +1966,21 @@ }, { "name": "utopia-php/migration", - "version": "0.4.1", + "version": "0.4.4", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "ae3cfe93f6d313105d226aeb68806660c806a925" + "reference": "a8a5d392bebf082faf289f4dfe09d9fd76844c33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/ae3cfe93f6d313105d226aeb68806660c806a925", - "reference": "ae3cfe93f6d313105d226aeb68806660c806a925", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/a8a5d392bebf082faf289f4dfe09d9fd76844c33", + "reference": "a8a5d392bebf082faf289f4dfe09d9fd76844c33", "shasum": "" }, "require": { "appwrite/appwrite": "10.1.0", - "php": "8.*", - "utopia-php/cli": "0.*" + "php": "8.*" }, "require-dev": { "laravel/pint": "1.*", @@ -2008,9 +2007,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.4.1" + "source": "https://github.com/utopia-php/migration/tree/0.4.4" }, - "time": "2024-05-01T13:19:18+00:00" + "time": "2024-05-17T05:25:31+00:00" }, { "name": "utopia-php/mongo", @@ -2124,16 +2123,16 @@ }, { "name": "utopia-php/platform", - "version": "0.5.1", + "version": "0.5.2", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "3eceef0b6593fe0f7d2efd36d40402a395a4c285" + "reference": "b9feabc79b92dc2b05683a986ad43bce5c1583e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/3eceef0b6593fe0f7d2efd36d40402a395a4c285", - "reference": "3eceef0b6593fe0f7d2efd36d40402a395a4c285", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/b9feabc79b92dc2b05683a986ad43bce5c1583e3", + "reference": "b9feabc79b92dc2b05683a986ad43bce5c1583e3", "shasum": "" }, "require": { @@ -2141,7 +2140,7 @@ "ext-redis": "*", "php": ">=8.0", "utopia-php/cli": "0.15.*", - "utopia-php/framework": "0.*.*" + "utopia-php/framework": "0.33.*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -2167,9 +2166,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/0.5.1" + "source": "https://github.com/utopia-php/platform/tree/0.5.2" }, - "time": "2023-12-26T16:14:41+00:00" + "time": "2024-05-22T12:50:35+00:00" }, { "name": "utopia-php/pools", @@ -2499,16 +2498,16 @@ }, { "name": "utopia-php/vcs", - "version": "0.6.5", + "version": "0.6.6", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2" + "reference": "e538264cfee5e3efdfe1771efba04750cf20b2c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", - "reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/e538264cfee5e3efdfe1771efba04750cf20b2c4", + "reference": "e538264cfee5e3efdfe1771efba04750cf20b2c4", "shasum": "" }, "require": { @@ -2542,9 +2541,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/0.6.5" + "source": "https://github.com/utopia-php/vcs/tree/0.6.6" }, - "time": "2024-01-08T17:11:12+00:00" + "time": "2024-05-17T09:36:30+00:00" }, { "name": "utopia-php/websocket", @@ -2731,29 +2730,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", -<<<<<<< HEAD - "version": "0.37.12", + "version": "0.38.6", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "882881934e8014b2135590e7ea5f402ab4513c38" + "reference": "d7016d6d72545e84709892faca972eb4bf5bd699" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/882881934e8014b2135590e7ea5f402ab4513c38", - "reference": "882881934e8014b2135590e7ea5f402ab4513c38", -======= - "version": "0.38.2", - "source": { - "type": "git", - "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "51284668529e2b10ed933412a42b603c76cded23" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/51284668529e2b10ed933412a42b603c76cded23", - "reference": "51284668529e2b10ed933412a42b603c76cded23", ->>>>>>> 1.6.x + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/d7016d6d72545e84709892faca972eb4bf5bd699", + "reference": "d7016d6d72545e84709892faca972eb4bf5bd699", "shasum": "" }, "require": { @@ -2789,15 +2775,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", -<<<<<<< HEAD - "source": "https://github.com/appwrite/sdk-generator/tree/0.37.12" + "source": "https://github.com/appwrite/sdk-generator/tree/0.38.6" }, - "time": "2024-04-17T19:14:43+00:00" -======= - "source": "https://github.com/appwrite/sdk-generator/tree/0.38.2" - }, - "time": "2024-04-25T07:49:29+00:00" ->>>>>>> 1.6.x + "time": "2024-05-20T18:00:16+00:00" }, { "name": "doctrine/deprecations", @@ -2918,16 +2898,16 @@ }, { "name": "laravel/pint", - "version": "v1.15.3", + "version": "v1.16.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656" + "reference": "1b3a3dc5bc6a81ff52828ba7277621f1d49d6d98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/3600b5d17aff52f6100ea4921849deacbbeb8656", - "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656", + "url": "https://api.github.com/repos/laravel/pint/zipball/1b3a3dc5bc6a81ff52828ba7277621f1d49d6d98", + "reference": "1b3a3dc5bc6a81ff52828ba7277621f1d49d6d98", "shasum": "" }, "require": { @@ -2938,11 +2918,11 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.54.0", - "illuminate/view": "^10.48.8", - "larastan/larastan": "^2.9.5", - "laravel-zero/framework": "^10.3.0", - "mockery/mockery": "^1.6.11", + "friendsofphp/php-cs-fixer": "^3.57.1", + "illuminate/view": "^10.48.10", + "larastan/larastan": "^2.9.6", + "laravel-zero/framework": "^10.4.0", + "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^1.15.1", "pestphp/pest": "^2.34.7" }, @@ -2980,7 +2960,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-04-30T15:02:26+00:00" + "time": "2024-05-21T18:08:25+00:00" }, { "name": "matthiasmullie/minify", @@ -3396,16 +3376,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.4.0", + "version": "5.4.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "298d2febfe79d03fe714eb871d5538da55205b1a" + "reference": "9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/298d2febfe79d03fe714eb871d5538da55205b1a", - "reference": "298d2febfe79d03fe714eb871d5538da55205b1a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c", + "reference": "9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c", "shasum": "" }, "require": { @@ -3454,9 +3434,9 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.1" }, - "time": "2024-04-09T21:13:58+00:00" + "time": "2024-05-21T05:55:05+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -3587,16 +3567,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.28.0", + "version": "1.29.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" + "reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/536889f2b340489d328f5ffb7b02bb6b183ddedc", + "reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc", "shasum": "" }, "require": { @@ -3628,9 +3608,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.0" }, - "time": "2024-04-03T18:51:33+00:00" + "time": "2024-05-06T12:04:23+00:00" }, { "name": "phpunit/php-code-coverage", From 63a5b9eed37d1b1165065e98328dee7f646b132f Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 27 May 2024 18:25:11 +0530 Subject: [PATCH 18/31] Revert changes in app/console --- app/console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/console b/app/console index 0a007a3b1b..f483d9631d 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 0a007a3b1b6eafc39dc19b7129f41643102f9676 +Subproject commit f483d9631d6f21e94aedb20b5c37c56fea06c23e From 93b4bfe4df263d751cd39d969f00fec1191a675a Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 27 May 2024 18:31:35 +0530 Subject: [PATCH 19/31] Add one more cancel check --- src/Appwrite/Platform/Workers/Builds.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 5d561ce359..3361071579 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -495,6 +495,11 @@ class Builds extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { + return; + } + /** Update function schedule */ // Inform scheduler if function is still active From edafeece9b30434f9d081285844589a7d5278d93 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 29 May 2024 14:39:57 +0530 Subject: [PATCH 20/31] Add console info before return --- src/Appwrite/Platform/Workers/Builds.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index c1c28771a0..acb855a513 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -163,6 +163,7 @@ class Builds extends Action } if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } @@ -212,6 +213,7 @@ class Builds extends Action $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } @@ -393,6 +395,7 @@ class Builds extends Action $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } @@ -464,6 +467,7 @@ class Builds extends Action if ($err) { $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } throw $err; @@ -497,6 +501,7 @@ class Builds extends Action $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } @@ -512,6 +517,7 @@ class Builds extends Action } catch (\Throwable $th) { $build = $dbForProject->getDocument('builds', $buildId); if ($build->getAttribute('status') === 'cancelled') { + Console::info('Build has been cancelled'); return; } From 0eabff5faf16e6b924fea3d19353627f41c990f3 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 31 May 2024 01:53:29 +0530 Subject: [PATCH 21/31] Refactor builds document creation --- app/config/errors.php | 5 ++ app/controllers/api/functions.php | 101 ++++++----------------- app/controllers/api/vcs.php | 22 ----- src/Appwrite/Extend/Exception.php | 1 + src/Appwrite/Platform/Workers/Builds.php | 53 +++++++----- 5 files changed, 66 insertions(+), 116 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 05409cf8cb..bf0c6a04e2 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -541,6 +541,11 @@ return [ 'description' => 'Build with the requested ID is already in progress. Please wait before you can retry.', 'code' => 400, ], + Exception::BUILD_ALREADY_COMPLETED => [ + 'name' => Exception::BUILD_ALREADY_COMPLETED, + 'description' => 'Build with the requested ID is already completed and cannot be cancelled.', + 'code' => 400, + ], /** Deployments */ Exception::DEPLOYMENT_NOT_FOUND => [ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 1e8de09bd3..a96dd30064 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -118,28 +118,6 @@ $redeployVcs = function (Request $request, Document $function, Document $project 'activate' => true, ])); - $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => null, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'waiting', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => '', - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); - - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) @@ -1228,28 +1206,6 @@ App::post('/v1/functions/:functionId/deployments') $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment->setAttribute('size', $fileSize)->setAttribute('metadata', $metadata)); } - $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => null, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'waiting', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => strtolower($deviceForFunctions->getType()), - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); - - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - // Start the build $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) @@ -1528,28 +1484,6 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), ])); - $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => null, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'waiting', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => '', - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); - - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) @@ -1564,13 +1498,13 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') ->groups(['api', 'functions']) - ->desc('Update build status') + ->desc('Cancel deployment') ->label('scope', 'functions.write') ->label('audits.event', 'deployment.update') ->label('audits.resource', 'function/{request.functionId}') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'functions') - ->label('sdk.method', 'cancelBuild') + ->label('sdk.method', 'updateDeploymentBuild') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_BUILD) @@ -1596,15 +1530,34 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''))); if ($build->isEmpty()) { - throw new Exception(Exception::BUILD_NOT_FOUND); - } + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => DateTime::now(), + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'cancelled', //mark status as cancelled + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => DateTime::now(), + 'duration' => 0, + 'size' => 0 + ])); - if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { - throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Build is already completed and cannot be cancelled.'); + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + } else { + if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { + throw new Exception(Exception::BUILD_ALREADY_COMPLETED); + } + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); } - $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); - $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); $deleteBuild = $executor->deleteRuntime($project->getId(), $deploymentId . "-build"); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 434cf5cc1a..382689a2cc 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -241,28 +241,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } - $buildId = ID::unique(); - $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, - '$permissions' => [], - 'startTime' => null, - 'deploymentInternalId' => $deployment->getInternalId(), - 'deploymentId' => $deployment->getId(), - 'status' => 'waiting', - 'path' => '', - 'runtime' => $function->getAttribute('runtime'), - 'source' => $deployment->getAttribute('path', ''), - 'sourceType' => '', - 'logs' => '', - 'endTime' => null, - 'duration' => 0, - 'size' => 0 - ])); - - $deployment->setAttribute('buildId', $build->getId()); - $deployment->setAttribute('buildInternalId', $build->getInternalId()); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 08fb899992..6b34f9db65 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -163,6 +163,7 @@ class Exception extends \Exception public const BUILD_NOT_FOUND = 'build_not_found'; public const BUILD_NOT_READY = 'build_not_ready'; public const BUILD_IN_PROGRESS = 'build_in_progress'; + public const BUILD_ALREADY_COMPLETED = 'build_already_completed'; /** Execution */ public const EXECUTION_NOT_FOUND = 'execution_not_found'; diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index acb855a513..6214828bcc 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -5,7 +5,6 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Event; use Appwrite\Event\Func; use Appwrite\Event\Usage; -use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; @@ -21,6 +20,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Conflict; use Utopia\Database\Exception\Restricted; use Utopia\Database\Exception\Structure; +use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Logger\Log; use Utopia\Platform\Action; @@ -158,21 +158,34 @@ class Builds extends Action $durationStart = \microtime(true); $buildId = $deployment->getAttribute('buildId', ''); $build = $dbForProject->getDocument('builds', $buildId); + $isNewBuild = empty($buildId); if ($build->isEmpty()) { - throw new AppwriteException(AppwriteException::BUILD_NOT_FOUND); - } + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => $startTime, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'processing', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => strtolower($deviceForFunctions->getType()), + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); - if ($build->getAttribute('status') === 'cancelled') { + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + } elseif ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } - $isNewBuild = empty($build->getAttribute('startTime')); - $build->setAttribute('status', 'processing'); - $build->setAttribute('startTime', $startTime); - $build->setAttribute('sourceType', strtolower($deviceForFunctions->getType())); - $build = $dbForProject->updateDocument('builds', $buildId, $build); - $source = $deployment->getAttribute('path', ''); $installationId = $deployment->getAttribute('installationId', ''); $providerRepositoryId = $deployment->getAttribute('providerRepositoryId', ''); @@ -211,8 +224,8 @@ class Builds extends Action $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + $build1 = $dbForProject->getDocument('builds', $buildId); + if ($build1->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -393,8 +406,8 @@ class Builds extends Action $response = null; $err = null; - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + $build1 = $dbForProject->getDocument('builds', $buildId); + if ($build1->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -465,8 +478,8 @@ class Builds extends Action ]); if ($err) { - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + $build1 = $dbForProject->getDocument('builds', $buildId); + if ($build1->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -499,8 +512,8 @@ class Builds extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + $build1 = $dbForProject->getDocument('builds', $buildId); + if ($build1->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -515,8 +528,8 @@ class Builds extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); } catch (\Throwable $th) { - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + $build1 = $dbForProject->getDocument('builds', $buildId); + if ($build1->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } From 2643202c97c7a78ad024a937c03784be58c5707d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sun, 2 Jun 2024 23:04:49 +0530 Subject: [PATCH 22/31] Replaced build1 with build --- src/Appwrite/Platform/Workers/Builds.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 6214828bcc..3f377c87f0 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -224,8 +224,8 @@ class Builds extends Action $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); - $build1 = $dbForProject->getDocument('builds', $buildId); - if ($build1->getAttribute('status') === 'cancelled') { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -406,8 +406,8 @@ class Builds extends Action $response = null; $err = null; - $build1 = $dbForProject->getDocument('builds', $buildId); - if ($build1->getAttribute('status') === 'cancelled') { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -478,8 +478,8 @@ class Builds extends Action ]); if ($err) { - $build1 = $dbForProject->getDocument('builds', $buildId); - if ($build1->getAttribute('status') === 'cancelled') { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -512,8 +512,8 @@ class Builds extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } - $build1 = $dbForProject->getDocument('builds', $buildId); - if ($build1->getAttribute('status') === 'cancelled') { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -528,8 +528,8 @@ class Builds extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); } catch (\Throwable $th) { - $build1 = $dbForProject->getDocument('builds', $buildId); - if ($build1->getAttribute('status') === 'cancelled') { + $build = $dbForProject->getDocument('builds', $buildId); + if ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } From d233f1ac643d481616222f6649f997abb9ccbaae Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:53:33 +0530 Subject: [PATCH 23/31] Update duration and endTime --- app/controllers/api/functions.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 82216f0bf5..a6f9ebe8b0 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1550,7 +1550,29 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); + $startTime = new \DateTime($build->getAttribute('startTime')); + $endTime = new \DateTime(); + $interval = $startTime->diff($endTime); + + $minuteInSeconds = 60; + $hourInSeconds = $minuteInSeconds * 60; + $dayInSeconds = $hourInSeconds * 24; + $monthInSeconds = $dayInSeconds * 30; + $yearsInSeconds = $monthInSeconds * 12; + + $duration = 0; + $duration += $interval->s; + $duration += $interval->i * $minuteInSeconds; + $duration += $interval->h * $hourInSeconds; + $duration += $interval->d * $dayInSeconds; + $duration += $interval->m * $monthInSeconds; + $duration += $interval->y * $yearsInSeconds; + + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttributes([ + 'endTime' => DateTime::now(), + 'duration' => $duration, + 'status' => 'cancelled' + ])); } $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); From 97786a05fff860e56a92e22d8f3fc63cba08094c Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:29:24 +0530 Subject: [PATCH 24/31] Updated cancelled build duration --- app/controllers/api/functions.php | 22 +++++----------------- src/Appwrite/Platform/Workers/Builds.php | 17 +++++++---------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index a6f9ebe8b0..4d4abe7938 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1550,23 +1550,11 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - $startTime = new \DateTime($build->getAttribute('startTime')); - $endTime = new \DateTime(); - $interval = $startTime->diff($endTime); - - $minuteInSeconds = 60; - $hourInSeconds = $minuteInSeconds * 60; - $dayInSeconds = $hourInSeconds * 24; - $monthInSeconds = $dayInSeconds * 30; - $yearsInSeconds = $monthInSeconds * 12; - - $duration = 0; - $duration += $interval->s; - $duration += $interval->i * $minuteInSeconds; - $duration += $interval->h * $hourInSeconds; - $duration += $interval->d * $dayInSeconds; - $duration += $interval->m * $monthInSeconds; - $duration += $interval->y * $yearsInSeconds; + $startTime = $build->getAttribute('startTime'); + $endTime = DateTime::now(); + $startTime = strtotime($startTime); + $endTime = strtotime($endTime); + $duration = $endTime - $startTime; $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttributes([ 'endTime' => DateTime::now(), diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 3f377c87f0..f11ac50164 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -184,6 +184,8 @@ class Builds extends Action } elseif ($build->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; + } else { + $build = $dbForProject->getDocument('builds', $buildId); } $source = $deployment->getAttribute('path', ''); @@ -224,8 +226,7 @@ class Builds extends Action $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -406,8 +407,7 @@ class Builds extends Action $response = null; $err = null; - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -478,8 +478,7 @@ class Builds extends Action ]); if ($err) { - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -512,8 +511,7 @@ class Builds extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } @@ -528,8 +526,7 @@ class Builds extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); } catch (\Throwable $th) { - $build = $dbForProject->getDocument('builds', $buildId); - if ($build->getAttribute('status') === 'cancelled') { + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { Console::info('Build has been cancelled'); return; } From 67b32ecb053c9fe919add9e0d974cfd9a33c2de4 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:41:13 +0100 Subject: [PATCH 25/31] test: cancel deployment --- app/controllers/api/functions.php | 2 +- .../Functions/FunctionsCustomServerTest.php | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 4d4abe7938..28512f0d5e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1532,7 +1532,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') 'startTime' => DateTime::now(), 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), - 'status' => 'cancelled', //mark status as cancelled + 'status' => 'cancelled', 'path' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path', ''), diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 6a8dc322e3..8facf9cc69 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -434,6 +434,73 @@ class FunctionsCustomServerTest extends Scope return array_merge($data, ['deploymentId' => $deploymentId]); } + /** + * @depends testCreateDeployment + */ + public function testCancelDeploymentBuild($data): void + { + // Create a new deployment to cancel + $folder = 'php'; + $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; + $this->packageCode($folder); + + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/deployments', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'code' => new CURLFile($code, 'application/x-gzip', \basename($code)), + 'activate' => true + ]); + + $deploymentId = $deployment['body']['$id'] ?? ''; + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + $this->assertEquals(true, (new DatetimeValidator())->isValid($deployment['body']['$createdAt'])); + $this->assertEquals('index.php', $deployment['body']['entrypoint']); + + // Poll until deployment is in progress + while (true) { + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + if ( + $deployment['headers']['status-code'] >= 400 + || $deployment['body']['status'] === 'building' + ) { + break; + } + + \sleep(1); + } + + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('building', $deployment['body']['status']); + + // Cancel the deployment build + $cancel = $this->client->call(Client::METHOD_PATCH, '/functions/' . $data['functionId'] . '/deployments/' . $deploymentId . '/build', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $cancel['headers']['status-code']); + $this->assertEquals('cancelled', $cancel['body']['status']); + + // Confirm the deployment is cancelled + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('cancelled', $deployment['body']['status']); + } + /** * @depends testUpdate */ From 853ffe804eaa100a698ab53c4c873c1f2848d4d5 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:48:55 +0100 Subject: [PATCH 26/31] feat: improve duration calc --- app/controllers/api/functions.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 28512f0d5e..e5f5212058 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1550,11 +1550,10 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - $startTime = $build->getAttribute('startTime'); - $endTime = DateTime::now(); - $startTime = strtotime($startTime); - $endTime = strtotime($endTime); - $duration = $endTime - $startTime; + + $startTime = new \DateTime($build->getAttribute('startTime')); + $endTime = new \DateTime('now'); + $duration = $endTime->getTimestamp() - $startTime->getTimestamp(); $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttributes([ 'endTime' => DateTime::now(), From 1269397475a9fb6cc71e0265fe42443c3fc8ceb8 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:50:50 +0100 Subject: [PATCH 27/31] chore: fmt --- app/controllers/api/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index e5f5212058..64249e6061 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1550,7 +1550,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { throw new Exception(Exception::BUILD_ALREADY_COMPLETED); } - + $startTime = new \DateTime($build->getAttribute('startTime')); $endTime = new \DateTime('now'); $duration = $endTime->getTimestamp() - $startTime->getTimestamp(); From 682b854aad06d689a00932e2f5445c1803175a30 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:01:56 +0100 Subject: [PATCH 28/31] test: fix functions test --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 8facf9cc69..02485379cf 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -435,7 +435,7 @@ class FunctionsCustomServerTest extends Scope } /** - * @depends testCreateDeployment + * @depends testUpdate */ public function testCancelDeploymentBuild($data): void { @@ -590,7 +590,7 @@ class FunctionsCustomServerTest extends Scope ], $this->getHeaders())); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertEquals($function['body']['total'], 2); + $this->assertEquals($function['body']['total'], 3); $this->assertIsArray($function['body']['deployments']); $this->assertCount(2, $function['body']['deployments']); From d6bfe084c162a07e60d311186743932365287a12 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:27:22 +0100 Subject: [PATCH 29/31] fix: tests --- .../Functions/FunctionsCustomServerTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 02485379cf..7a70b45380 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -592,7 +592,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals($function['body']['total'], 3); $this->assertIsArray($function['body']['deployments']); - $this->assertCount(2, $function['body']['deployments']); + $this->assertCount(3, $function['body']['deployments']); /** * Test search queries @@ -605,9 +605,9 @@ class FunctionsCustomServerTest extends Scope ])); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertEquals(2, $function['body']['total']); + $this->assertEquals(3, $function['body']['total']); $this->assertIsArray($function['body']['deployments']); - $this->assertCount(2, $function['body']['deployments']); + $this->assertCount(3, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); $function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ @@ -632,7 +632,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertCount(1, $function['body']['deployments']); + $this->assertCount(2, $function['body']['deployments']); $function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ 'content-type' => 'application/json', @@ -644,7 +644,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertCount(2, $function['body']['deployments']); + $this->assertCount(3, $function['body']['deployments']); $function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ 'content-type' => 'application/json', @@ -666,9 +666,9 @@ class FunctionsCustomServerTest extends Scope ])); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertEquals(2, $function['body']['total']); + $this->assertEquals(3, $function['body']['total']); $this->assertIsArray($function['body']['deployments']); - $this->assertCount(2, $function['body']['deployments']); + $this->assertCount(3, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); $function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ @@ -679,9 +679,9 @@ class FunctionsCustomServerTest extends Scope ])); $this->assertEquals($function['headers']['status-code'], 200); - $this->assertEquals(2, $function['body']['total']); + $this->assertEquals(3, $function['body']['total']); $this->assertIsArray($function['body']['deployments']); - $this->assertCount(2, $function['body']['deployments']); + $this->assertCount(3, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); return $data; From 7559c9af68e32148c1de1438639360fa8c1adb2c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:21:48 +0100 Subject: [PATCH 30/31] chore: us spelling of canceled --- app/config/errors.php | 2 +- app/controllers/api/functions.php | 4 ++-- src/Appwrite/Platform/Workers/Builds.php | 24 +++++++++---------- .../Functions/FunctionsCustomServerTest.php | 6 ++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index bf0c6a04e2..66178bcf7d 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -543,7 +543,7 @@ return [ ], Exception::BUILD_ALREADY_COMPLETED => [ 'name' => Exception::BUILD_ALREADY_COMPLETED, - 'description' => 'Build with the requested ID is already completed and cannot be cancelled.', + 'description' => 'Build with the requested ID is already completed and cannot be canceled.', 'code' => 400, ], diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 64249e6061..f0e75d3b9d 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1532,7 +1532,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') 'startTime' => DateTime::now(), 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), - 'status' => 'cancelled', + 'status' => 'canceled', 'path' => '', 'runtime' => $function->getAttribute('runtime'), 'source' => $deployment->getAttribute('path', ''), @@ -1558,7 +1558,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttributes([ 'endTime' => DateTime::now(), 'duration' => $duration, - 'status' => 'cancelled' + 'status' => 'canceled' ])); } diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index f11ac50164..02ca13ae85 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -181,8 +181,8 @@ class Builds extends Action $deployment->setAttribute('buildId', $build->getId()); $deployment->setAttribute('buildInternalId', $build->getInternalId()); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - } elseif ($build->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + } elseif ($build->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } else { $build = $dbForProject->getDocument('builds', $buildId); @@ -226,8 +226,8 @@ class Builds extends Action $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); - if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } @@ -407,8 +407,8 @@ class Builds extends Action $response = null; $err = null; - if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } @@ -478,8 +478,8 @@ class Builds extends Action ]); if ($err) { - if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } throw $err; @@ -511,8 +511,8 @@ class Builds extends Action $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } - if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } @@ -526,8 +526,8 @@ class Builds extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); } catch (\Throwable $th) { - if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'cancelled') { - Console::info('Build has been cancelled'); + if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { + Console::info('Build has been canceled'); return; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 7a70b45380..4b2a8e0bc7 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -488,9 +488,9 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(200, $cancel['headers']['status-code']); - $this->assertEquals('cancelled', $cancel['body']['status']); + $this->assertEquals('canceled', $cancel['body']['status']); - // Confirm the deployment is cancelled + // Confirm the deployment is canceled $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $deploymentId, [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -498,7 +498,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(200, $deployment['headers']['status-code']); - $this->assertEquals('cancelled', $deployment['body']['status']); + $this->assertEquals('canceled', $deployment['body']['status']); } /** From 0a78d41ecbefcaba0a2426fc6916142a1b9200ce Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:50:18 +0100 Subject: [PATCH 31/31] chore: remove endTime --- app/controllers/api/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f0e75d3b9d..068fc1c836 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1538,7 +1538,6 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build') 'source' => $deployment->getAttribute('path', ''), 'sourceType' => '', 'logs' => '', - 'endTime' => DateTime::now(), 'duration' => 0, 'size' => 0 ]));