Merge pull request #9455 from appwrite/chore-migrate-cancel-deployment-endpoint

Chore: Move cancel build to update deployment status
This commit is contained in:
Matej Bačo 2025-03-06 14:04:35 +01:00 committed by GitHub
commit 62b639ce48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 41 additions and 30 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Builds;
namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Status;
use Appwrite\Event\Event;
use Appwrite\Extend\Exception;
@ -25,15 +25,16 @@ class Update extends Action
public static function getName()
{
return 'updateDeploymentBuild';
return 'updateDeploymentStatus';
}
public function __construct()
{
$this
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/build')
->desc('Cancel deployment')
->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/status')
->httpAlias('/v1/functions/:functionId/deployments/:deploymentId/build')
->desc('Update deployment status')
->groups(['api', 'functions'])
->label('scope', 'functions.write')
->label('resourceType', RESOURCE_TYPE_FUNCTIONS)
@ -41,7 +42,7 @@ class Update extends Action
->label('audits.resource', 'function/{request.functionId}')
->label('sdk', new Method(
namespace: 'functions',
name: 'updateDeploymentBuild',
name: 'updateDeploymentStatus',
description: <<<EOT
Cancel an ongoing function deployment build. If the build is already in progress, it will be stopped and marked as canceled. If the build hasn't started yet, it will be marked as canceled without executing. You cannot cancel builds that have already completed (status 'ready') or failed. The response includes the final build status and details.
EOT,

View file

@ -2,12 +2,12 @@
namespace Appwrite\Platform\Modules\Functions\Services;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Builds\Update as UpdateBuild;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Create as CreateDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Delete as DeleteDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Download\Get as DownloadDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Duplicate\Create as CreateDuplicateDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Get as GetDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Status\Update as UpdateDeploymentStatus;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Template\Create as CreateTemplateDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\Vcs\Create as CreateVcsDeployment;
use Appwrite\Platform\Modules\Functions\Http\Deployments\XList as ListDeployments;
@ -63,7 +63,7 @@ class Http extends Service
$this->addAction(CreateVcsDeployment::getName(), new CreateVcsDeployment());
$this->addAction(DownloadDeployment::getName(), new DownloadDeployment());
$this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment());
$this->addAction(UpdateBuild::getName(), new UpdateBuild());
$this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus());
// Executions
$this->addAction(CreateExecution::getName(), new CreateExecution());

View file

@ -1,6 +1,6 @@
<?php
namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Builds;
namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Status;
use Appwrite\Event\Event;
use Appwrite\Extend\Exception;
@ -25,22 +25,22 @@ class Update extends Action
public static function getName()
{
return 'updateDeploymentBuild';
return 'updateDeploymentStatus';
}
public function __construct()
{
$this
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/build')
->desc('Cancel deployment')
->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/status')
->desc('Update deployment status')
->groups(['api', 'sites'])
->label('scope', 'sites.write')
->label('audits.event', 'deployment.update')
->label('audits.resource', 'site/{request.siteId}')
->label('sdk', new Method(
namespace: 'sites',
name: 'updateDeploymentBuild',
name: 'updateDeploymentStatus',
description: <<<EOT
Cancel an ongoing site deployment build. If the build is already in progress, it will be stopped and marked as canceled. If the build hasn't started yet, it will be marked as canceled without executing. You cannot cancel builds that have already completed (status 'ready') or failed. The response includes the final build status and details.
EOT,

View file

@ -2,12 +2,12 @@
namespace Appwrite\Platform\Modules\Sites\Services;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Builds\Update as UpdateBuild;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Create as CreateDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Delete as DeleteDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Download\Get as DownloadDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Duplicate\Create as CreateDuplicateDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Get as GetDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Status\Update as UpdateDeploymentStatus;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Template\Create as CreateTemplateDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\Vcs\Create as CreateVcsDeployment;
use Appwrite\Platform\Modules\Sites\Http\Deployments\XList as ListDeployments;
@ -58,7 +58,7 @@ class Http extends Service
$this->addAction(DeleteDeployment::getName(), new DeleteDeployment());
$this->addAction(DownloadDeployment::getName(), new DownloadDeployment());
$this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment());
$this->addAction(UpdateBuild::getName(), new UpdateBuild());
$this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus());
// Logs
$this->addAction(GetLog::getName(), new GetLog());

View file

@ -379,4 +379,14 @@ trait FunctionsBase
return $function;
}
protected function cancelDeployment(string $functionId, string $deploymentId): mixed
{
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId . '/status', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $deployment;
}
}

View file

@ -536,14 +536,9 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals('building', $deployment['body']['status']);
}, 100000, 250);
// Cancel the deployment
$cancel = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId . '/build', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $cancel['headers']['status-code']);
$this->assertEquals('canceled', $cancel['body']['status']);
$deployment = $this->cancelDeployment($functionId, $deploymentId);
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('canceled', $deployment['body']['status']);
/**
* Build worker still runs the build.

View file

@ -404,4 +404,14 @@ trait SitesBase
return $site;
}
protected function cancelDeployment(string $siteId, string $deploymentId): mixed
{
$deployment = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId . '/status', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $deployment;
}
}

View file

@ -708,14 +708,9 @@ class SitesCustomServerTest extends Scope
$this->assertEquals('building', $deployment['body']['status']);
}, 100000, 250);
// Cancel the deployment
$cancel = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId . '/build', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $cancel['headers']['status-code']);
$this->assertEquals('canceled', $cancel['body']['status']);
$deployment = $this->cancelDeployment($siteId, $deploymentId);
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('canceled', $deployment['body']['status']);
/**
* Build worker still runs the build.