feat: Remove builds param from delete endpoint
This commit is contained in:
parent
b80965edd8
commit
19c9ee4dc6
3 changed files with 20 additions and 29 deletions
|
@ -3,7 +3,6 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
|
||||
use Appwrite\Runtimes\Runtimes;
|
||||
use Swoole\ConnectionPool;
|
||||
use Swoole\Coroutine as Co;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
use Swoole\Http\Server;
|
||||
|
@ -19,12 +18,10 @@ use Utopia\Storage\Device\Local;
|
|||
use Utopia\Storage\Storage;
|
||||
use Utopia\Swoole\Request;
|
||||
use Utopia\Swoole\Response;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Assoc;
|
||||
use Utopia\Validator\Range as ValidatorRange;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
|
||||
// TODO
|
||||
// Implement other endpoints - Done
|
||||
// Handle shutdown - Done
|
||||
|
@ -43,7 +40,6 @@ use Utopia\Validator\Text;
|
|||
// Fix delete endpoint
|
||||
// Add size validators for the runtime IDs
|
||||
// Decide on logic for build and runtime containers names ( runtime-ID and build-ID)
|
||||
//
|
||||
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
|
@ -444,25 +440,28 @@ App::get('/v1/runtimes/:runtimeId')
|
|||
App::delete('/v1/runtimes/:runtimeId')
|
||||
->desc('Delete a runtime')
|
||||
->param('runtimeId', '', new Text(128), 'Runtime unique ID.', false)
|
||||
->param('buildIds', [], new ArrayList(new Text(0), 100), 'List of build IDs to delete.', false)
|
||||
->inject('orchestrationPool')
|
||||
->inject('activeRuntimes')
|
||||
->inject('response')
|
||||
->action(function (string $runtimeId, array $buildIds, $orchestrationPool, $activeRuntimes, Response $response) {
|
||||
|
||||
Console::info('Deleting runtime: ' . $runtimeId);
|
||||
$orchestration = $orchestrationPool->get();
|
||||
->action(function (string $runtimeId, $orchestrationPool, $activeRuntimes, Response $response) {
|
||||
|
||||
$container = 'runtime-' . $runtimeId;
|
||||
$status = $orchestration->remove($container, true);
|
||||
if ($status) {
|
||||
Console::success('Removed runtime container: ' . $runtimeId);
|
||||
} else {
|
||||
Console::info('Deleting runtime: ' . $container);
|
||||
try {
|
||||
$orchestration = $orchestrationPool->get();
|
||||
$status = $orchestration->remove($container, true);
|
||||
if ($status) {
|
||||
Console::success('Removed runtime container: ' . $runtimeId);
|
||||
} else {
|
||||
Console::error('Failed to remove runtime container: ' . $runtimeId);
|
||||
}
|
||||
$activeRuntimes->del($container);
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('Failed to remove runtime container: ' . $runtimeId);
|
||||
} finally {
|
||||
$orchestrationPool->put($orchestration);
|
||||
}
|
||||
|
||||
$activeRuntimes->del($container);
|
||||
|
||||
// Remove all the build containers with that same ID
|
||||
// TODO:: Delete build containers
|
||||
// foreach ($buildIds as $buildId) {
|
||||
|
@ -474,8 +473,6 @@ App::delete('/v1/runtimes/:runtimeId')
|
|||
// }
|
||||
// }
|
||||
|
||||
$orchestrationPool->put($orchestration);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_OK)
|
||||
->send();
|
||||
|
|
|
@ -336,12 +336,10 @@ class DeletesV1 extends Worker
|
|||
*/
|
||||
Console::info("Deleting builds for function " . $functionId);
|
||||
$storageBuilds = new Local(APP_STORAGE_BUILDS . '/app-' . $projectId);
|
||||
$buildIds = [];
|
||||
foreach ($deploymentIds as $deploymentId) {
|
||||
$this->deleteByGroup('builds', [
|
||||
new Query('deploymentId', Query::TYPE_EQUAL, [$deploymentId])
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds, $deploymentId, &$buildIds) {
|
||||
$buildIds[$deploymentId][] = $document->getId();
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds, $deploymentId) {
|
||||
if ($storageBuilds->delete($document->getAttribute('outputPath', ''), true)) {
|
||||
Console::success('Deleted build files: ' . $document->getAttribute('outputPath', ''));
|
||||
} else {
|
||||
|
@ -365,7 +363,7 @@ class DeletesV1 extends Worker
|
|||
$executor = new Executor();
|
||||
foreach ($deploymentIds as $deploymentId) {
|
||||
try {
|
||||
$executor->deleteRuntime($projectId, $functionId, $deploymentId, $buildIds[$deploymentId]);
|
||||
$executor->deleteRuntime($projectId, $functionId, $deploymentId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
@ -398,12 +396,10 @@ class DeletesV1 extends Worker
|
|||
* Delete builds
|
||||
*/
|
||||
Console::info("Deleting builds for deployment " . $deploymentId);
|
||||
$buildIds = [];
|
||||
$storageBuilds = new Local(APP_STORAGE_BUILDS . '/app-' . $projectId);
|
||||
$this->deleteByGroup('builds', [
|
||||
new Query('deploymentId', Query::TYPE_EQUAL, [$deploymentId])
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds, &$buildIds) {
|
||||
$buildIds[] = $document->getId();
|
||||
], $dbForProject, function (Document $document) use ($storageBuilds) {
|
||||
if ($storageBuilds->delete($document->getAttribute('outputPath', ''), true)) {
|
||||
Console::success('Deleted build files: ' . $document->getAttribute('outputPath', ''));
|
||||
} else {
|
||||
|
@ -417,7 +413,7 @@ class DeletesV1 extends Worker
|
|||
Console::info("Requesting executor to delete deployment container for deployment " . $deploymentId);
|
||||
try {
|
||||
$executor = new Executor();
|
||||
$executor->deleteRuntime($projectId, $functionId, $deploymentId, $buildIds);
|
||||
$executor->deleteRuntime($projectId, $functionId, $deploymentId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class Executor
|
|||
return $response['body'];
|
||||
}
|
||||
|
||||
public function deleteRuntime(string $projectId, string $functionId, string $deploymentId, array $buildIds)
|
||||
public function deleteRuntime(string $projectId, string $functionId, string $deploymentId)
|
||||
{
|
||||
$runtimeId = "$projectId-$deploymentId";
|
||||
$route = "/runtimes/$runtimeId";
|
||||
|
@ -75,9 +75,7 @@ class Executor
|
|||
'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
];
|
||||
|
||||
$params = [
|
||||
'buildIds' => $buildIds,
|
||||
];
|
||||
$params = [];
|
||||
|
||||
$response = $this->call(self::METHOD_DELETE, $route, $headers, $params, true, 30);
|
||||
|
||||
|
|
Loading…
Reference in a new issue