feat: add deploymentId property to builds collection
This commit is contained in:
parent
ada65e9819
commit
a82562c16e
|
@ -2049,6 +2049,17 @@ $collections = [
|
|||
'$id' => 'builds',
|
||||
'name' => 'Builds',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => 'deploymentId',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'dateCreated',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
|
@ -2173,9 +2184,9 @@ $collections = [
|
|||
],
|
||||
'indexes' => [
|
||||
[
|
||||
'$id' => '_key_status',
|
||||
'$id' => '_key_deployment',
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['status'],
|
||||
'attributes' => ['deploymentId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
|
|
|
@ -431,34 +431,34 @@ App::delete('/v1/functions/:functionId')
|
|||
|
||||
$function = $dbForProject->getDocument('functions', $functionId);
|
||||
|
||||
// Request executor to delete deployment containers
|
||||
$ch = \curl_init();
|
||||
\curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor/v1/functions/$functionId");
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
\curl_setopt($ch, CURLOPT_TIMEOUT, 900);
|
||||
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
\curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'x-appwrite-project: '.$project->getId(),
|
||||
'x-appwrite-executor-key: '. App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
]);
|
||||
// // Request executor to delete deployment containers
|
||||
// $ch = \curl_init();
|
||||
// \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
// \curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor/v1/functions/$functionId");
|
||||
// \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// \curl_setopt($ch, CURLOPT_TIMEOUT, 900);
|
||||
// \curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
// \curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
// 'Content-Type: application/json',
|
||||
// 'x-appwrite-project: '.$project->getId(),
|
||||
// 'x-appwrite-executor-key: '. App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
// ]);
|
||||
|
||||
$executorResponse = \curl_exec($ch);
|
||||
// $executorResponse = \curl_exec($ch);
|
||||
|
||||
$error = \curl_error($ch);
|
||||
// $error = \curl_error($ch);
|
||||
|
||||
if (!empty($error)) {
|
||||
throw new Exception('Executor Cleanup Error: ' . $error, 500);
|
||||
}
|
||||
// if (!empty($error)) {
|
||||
// throw new Exception('Executor Cleanup Error: ' . $error, 500);
|
||||
// }
|
||||
|
||||
// Check status code
|
||||
$statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if (200 !== $statusCode) {
|
||||
throw new Exception('Executor error: ' . $executorResponse, $statusCode);
|
||||
}
|
||||
// // Check status code
|
||||
// $statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
// if (200 !== $statusCode) {
|
||||
// throw new Exception('Executor error: ' . $executorResponse, $statusCode);
|
||||
// }
|
||||
|
||||
\curl_close($ch);
|
||||
// \curl_close($ch);
|
||||
|
||||
if ($function->isEmpty()) {
|
||||
throw new Exception('Function not found', 404);
|
||||
|
|
|
@ -413,6 +413,7 @@ function execute(string $trigger, string $projectId, string $executionId, string
|
|||
'$id' => $buildId,
|
||||
'$read' => ($userId !== '') ? ['user:' . $userId] : [],
|
||||
'$write' => [],
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'dateCreated' => time(),
|
||||
'status' => 'processing',
|
||||
'outputPath' => '',
|
||||
|
|
|
@ -100,6 +100,7 @@ const DELETE_TYPE_DOCUMENT = 'document';
|
|||
const DELETE_TYPE_COLLECTIONS = 'collections';
|
||||
const DELETE_TYPE_PROJECTS = 'projects';
|
||||
const DELETE_TYPE_FUNCTIONS = 'functions';
|
||||
const DELETE_TYPE_DEPLOYMENTS = 'deployments';
|
||||
const DELETE_TYPE_USERS = 'users';
|
||||
const DELETE_TYPE_TEAMS= 'teams';
|
||||
const DELETE_TYPE_EXECUTIONS = 'executions';
|
||||
|
|
|
@ -118,6 +118,7 @@ class BuildsV1 extends Worker
|
|||
'$id' => $buildId,
|
||||
'$read' => [],
|
||||
'$write' => [],
|
||||
'deploymentId' => $deploymentId,
|
||||
'dateCreated' => time(),
|
||||
'status' => 'processing',
|
||||
'runtime' => $function->getAttribute('runtime'),
|
||||
|
|
|
@ -50,6 +50,9 @@ class DeletesV1 extends Worker
|
|||
case DELETE_TYPE_FUNCTIONS:
|
||||
$this->deleteFunction($document, $projectId);
|
||||
break;
|
||||
case DELETE_TYPE_DEPLOYMENTS:
|
||||
$this->deleteDeployment($document, $projectId);
|
||||
break;
|
||||
case DELETE_TYPE_USERS:
|
||||
$this->deleteUser($document, $projectId);
|
||||
break;
|
||||
|
@ -313,18 +316,34 @@ class DeletesV1 extends Worker
|
|||
$this->deleteByGroup('deployments', [
|
||||
new Query('functionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], $dbForProject, function (Document $document) use ($device) {
|
||||
|
||||
if ($device->delete($document->getAttribute('path', ''))) {
|
||||
if ($device->delete($document->getAttribute('path', ''), true)) {
|
||||
Console::success('Delete code deployment: ' . $document->getAttribute('path', ''));
|
||||
} else {
|
||||
Console::error('Failed to delete code deployment: ' . $document->getAttribute('path', ''));
|
||||
}
|
||||
});
|
||||
|
||||
// Delete builds
|
||||
$this->deleteByGroup('builds', [
|
||||
new Query('functionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], $dbForProject, function (Document $document) use ($device) {
|
||||
if ($device->delete($document->getAttribute('path', ''), true)) {
|
||||
Console::success('Delete code deployment: ' . $document->getAttribute('path', ''));
|
||||
} else {
|
||||
Console::error('Failed to delete code deployment: ' . $document->getAttribute('path', ''));
|
||||
}
|
||||
});
|
||||
|
||||
// Delete build files
|
||||
|
||||
// Delete Executions
|
||||
$this->deleteByGroup('executions', [
|
||||
new Query('functionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], $dbForProject);
|
||||
|
||||
|
||||
// Delete deployment files
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue