mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
feat: Adding function statuses enum
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Functions\Status;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
@@ -3618,7 +3619,7 @@ $projectCollections = array_merge([
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => true,
|
||||
'default' => 'processing',
|
||||
'default' => Status::BUILDING,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
|
||||
@@ -10,6 +10,7 @@ use Appwrite\Event\Usage;
|
||||
use Appwrite\Event\Validator\FunctionEvent;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Messaging\Adapter\Realtime;
|
||||
use Appwrite\Platform\Tasks\ScheduleExecutions;
|
||||
use Appwrite\Task\Validator\Cron;
|
||||
@@ -965,7 +966,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId')
|
||||
throw new Exception(Exception::BUILD_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($build->getAttribute('status') !== 'ready') {
|
||||
if ($build->getAttribute('status') !== Status::READY) {
|
||||
throw new Exception(Exception::BUILD_NOT_READY);
|
||||
}
|
||||
|
||||
@@ -1319,7 +1320,7 @@ App::get('/v1/functions/:functionId/deployments')
|
||||
|
||||
foreach ($results as $result) {
|
||||
$build = $dbForProject->getDocument('builds', $result->getAttribute('buildId', ''));
|
||||
$result->setAttribute('status', $build->getAttribute('status', 'processing'));
|
||||
$result->setAttribute('status', $build->getAttribute('status', Status::BUILDING));
|
||||
$result->setAttribute('buildLogs', $build->getAttribute('logs', ''));
|
||||
$result->setAttribute('buildTime', $build->getAttribute('duration', 0));
|
||||
$result->setAttribute('size', $result->getAttribute('size', 0) + $build->getAttribute('size', 0));
|
||||
@@ -1365,7 +1366,7 @@ App::get('/v1/functions/:functionId/deployments/:deploymentId')
|
||||
}
|
||||
|
||||
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
|
||||
$deployment->setAttribute('status', $build->getAttribute('status', 'waiting'));
|
||||
$deployment->setAttribute('status', $build->getAttribute('status', Status::QUEUED));
|
||||
$deployment->setAttribute('buildLogs', $build->getAttribute('logs', ''));
|
||||
$deployment->setAttribute('buildTime', $build->getAttribute('duration', 0));
|
||||
$deployment->setAttribute('size', $deployment->getAttribute('size', 0) + $build->getAttribute('size', 0));
|
||||
@@ -1550,7 +1551,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/build')
|
||||
$deployment->setAttribute('buildInternalId', $build->getInternalId());
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
|
||||
} else {
|
||||
if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) {
|
||||
if (\in_array($build->getAttribute('status'), [Status::READY, Status::FAILED])) {
|
||||
throw new Exception(Exception::BUILD_ALREADY_COMPLETED);
|
||||
}
|
||||
|
||||
@@ -1643,7 +1644,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
throw new Exception(Exception::BUILD_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($build->getAttribute('status') !== 'ready') {
|
||||
if ($build->getAttribute('status') !== Status::READY) {
|
||||
throw new Exception(Exception::BUILD_NOT_READY);
|
||||
}
|
||||
|
||||
@@ -1712,10 +1713,10 @@ App::post('/v1/functions/:functionId/executions')
|
||||
|
||||
$executionId = ID::unique();
|
||||
|
||||
$status = $async ? 'waiting' : 'processing';
|
||||
$status = $async ? Status::QUEUED : Status::BUILDING;
|
||||
|
||||
if(!is_null($scheduledAt)) {
|
||||
$status = 'scheduled';
|
||||
$status = Status::SCHEDULED;
|
||||
}
|
||||
|
||||
$execution = new Document([
|
||||
@@ -1867,7 +1868,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
}
|
||||
|
||||
/** Update execution status */
|
||||
$status = $executionResponse['statusCode'] >= 400 ? 'failed' : 'completed';
|
||||
$status = $executionResponse['statusCode'] >= 400 ? Status::FAILED : Status::SUCCESSFUL;
|
||||
$execution->setAttribute('status', $status);
|
||||
$execution->setAttribute('responseStatusCode', $executionResponse['statusCode']);
|
||||
$execution->setAttribute('responseHeaders', $headersFiltered);
|
||||
@@ -1879,7 +1880,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
|
||||
$execution
|
||||
->setAttribute('duration', $durationEnd - $durationStart)
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('status', Status::FAILED)
|
||||
->setAttribute('responseStatusCode', 500)
|
||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||
Console::error($th->getMessage());
|
||||
@@ -2084,7 +2085,7 @@ App::delete('/v1/functions/:functionId/executions/:executionId')
|
||||
}
|
||||
$status = $execution->getAttribute('status');
|
||||
|
||||
if (!in_array($status, ['completed', 'failed', 'scheduled'])) {
|
||||
if (!in_array($status, [Status::SUCCESSFUL, Status::FAILED, Status::SCHEDULED])) {
|
||||
throw new Exception(Exception::EXECUTION_IN_PROGRESS);
|
||||
}
|
||||
|
||||
@@ -2092,7 +2093,7 @@ App::delete('/v1/functions/:functionId/executions/:executionId')
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove execution from DB');
|
||||
}
|
||||
|
||||
if ($status === 'scheduled') {
|
||||
if ($status === Status::SCHEDULED) {
|
||||
$schedule = $dbForConsole->findOne('schedules', [
|
||||
Query::equal('resourceId', [$execution->getId()]),
|
||||
Query::equal('resourceType', [ScheduleExecutions::getSupportedResource()]),
|
||||
|
||||
@@ -4,6 +4,7 @@ use Appwrite\Auth\OAuth2\Github as OAuth2Github;
|
||||
use Appwrite\Event\Build;
|
||||
use Appwrite\Event\Delete;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Installations;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
@@ -94,7 +95,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
|
||||
}
|
||||
}
|
||||
|
||||
$commentStatus = $isAuthorized ? 'waiting' : 'failed';
|
||||
$commentStatus = $isAuthorized ? Status::QUEUED : Status::FAILED;
|
||||
|
||||
$authorizeUrl = $request->getProtocol() . '://' . $request->getHostname() . "/git/authorize-contributor?projectId={$projectId}&installationId={$installationId}&repositoryId={$repositoryId}&providerPullRequestId={$providerPullRequestId}";
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Appwrite\Event\Certificate;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Request\Filters\V16 as RequestV16;
|
||||
@@ -156,7 +157,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
throw new AppwriteException(AppwriteException::BUILD_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($build->getAttribute('status') !== 'ready') {
|
||||
if ($build->getAttribute('status') !== Status::READY) {
|
||||
throw new AppwriteException(AppwriteException::BUILD_NOT_READY);
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
'deploymentInternalId' => $deployment->getInternalId(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'trigger' => 'http', // http / schedule / event
|
||||
'status' => 'processing', // waiting / processing / completed / failed
|
||||
'status' => Status::EXECUTING,
|
||||
'responseStatusCode' => 0,
|
||||
'responseHeaders' => [],
|
||||
'requestPath' => $path,
|
||||
@@ -302,7 +303,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
}
|
||||
|
||||
/** Update execution status */
|
||||
$status = $executionResponse['statusCode'] >= 400 ? 'failed' : 'completed';
|
||||
$status = $executionResponse['statusCode'] >= 400 ? Status::FAILED : Status::SUCCESSFUL;
|
||||
$execution->setAttribute('status', $status);
|
||||
$execution->setAttribute('responseStatusCode', $executionResponse['statusCode']);
|
||||
$execution->setAttribute('responseHeaders', $headersFiltered);
|
||||
@@ -315,7 +316,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
|
||||
$execution
|
||||
->setAttribute('duration', $durationEnd - $durationStart)
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('status', Status::FAILED)
|
||||
->setAttribute('responseStatusCode', 500)
|
||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||
Console::error($th->getMessage());
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Functions;
|
||||
|
||||
class Status
|
||||
{
|
||||
public const QUEUED = 'queued';
|
||||
public const CANCELLED = 'cancelled';
|
||||
public const FAILED = 'failed';
|
||||
|
||||
// For builds only
|
||||
public const READY = 'ready';
|
||||
public const BUILDING = 'building';
|
||||
|
||||
// For executions only
|
||||
public const EXECUTING = 'executing';
|
||||
public const SCHEDULED = 'scheduled';
|
||||
public const SUCCESSFUL = 'successful';
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Appwrite\Platform\Workers;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Func;
|
||||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Messaging\Adapter\Realtime;
|
||||
use Appwrite\Utopia\Response\Model\Deployment;
|
||||
use Appwrite\Vcs\Comment;
|
||||
@@ -167,7 +168,7 @@ class Builds extends Action
|
||||
'startTime' => $startTime,
|
||||
'deploymentInternalId' => $deployment->getInternalId(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'status' => 'processing',
|
||||
'status' => Status::BUILDING,
|
||||
'path' => '',
|
||||
'runtime' => $function->getAttribute('runtime'),
|
||||
'source' => $deployment->getAttribute('path', ''),
|
||||
@@ -334,15 +335,15 @@ class Builds extends Action
|
||||
|
||||
$build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('source', $source));
|
||||
|
||||
$this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction(Status::BUILDING, $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
|
||||
/** Request the executor to build the code... */
|
||||
$build->setAttribute('status', 'building');
|
||||
$build->setAttribute('status', Status::BUILDING);
|
||||
$build = $dbForProject->updateDocument('builds', $buildId, $build);
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('building', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction(Status::BUILDING, $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
|
||||
/** Trigger Webhook */
|
||||
@@ -496,13 +497,13 @@ class Builds extends Action
|
||||
$build->setAttribute('startTime', DateTime::format((new \DateTime())->setTimestamp(floor($response['startTime']))));
|
||||
$build->setAttribute('endTime', $endTime);
|
||||
$build->setAttribute('duration', \intval(\ceil($durationEnd - $durationStart)));
|
||||
$build->setAttribute('status', 'ready');
|
||||
$build->setAttribute('status', Status::READY);
|
||||
$build->setAttribute('path', $response['path']);
|
||||
$build->setAttribute('size', $response['size']);
|
||||
$build->setAttribute('logs', $response['output']);
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('ready', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction(Status::READY, $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
|
||||
Console::success("Build id: $buildId created");
|
||||
@@ -539,11 +540,11 @@ class Builds extends Action
|
||||
$durationEnd = \microtime(true);
|
||||
$build->setAttribute('endTime', $endTime);
|
||||
$build->setAttribute('duration', \intval(\ceil($durationEnd - $durationStart)));
|
||||
$build->setAttribute('status', 'failed');
|
||||
$build->setAttribute('status', Status::FAILED);
|
||||
$build->setAttribute('logs', $th->getMessage() . "\n" . $th->getFile() . ':' . $th->getLine() . "\n" . $th->getTraceAsString());
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction(Status::FAILED, $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
} finally {
|
||||
$build = $dbForProject->updateDocument('builds', $buildId, $build);
|
||||
@@ -566,13 +567,13 @@ class Builds extends Action
|
||||
);
|
||||
|
||||
/** Trigger usage queue */
|
||||
if ($build->getAttribute('status') === 'ready') {
|
||||
if ($build->getAttribute('status') === Status::READY) {
|
||||
$queueForUsage
|
||||
->addMetric(METRIC_BUILDS_SUCCESS, 1) // per project
|
||||
->addMetric(METRIC_BUILDS_COMPUTE_SUCCESS, (int)$build->getAttribute('duration', 0) * 1000)
|
||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_SUCCESS), 1) // per function
|
||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE_SUCCESS), (int)$build->getAttribute('duration', 0) * 1000);
|
||||
} elseif ($build->getAttribute('status') === 'failed') {
|
||||
} elseif ($build->getAttribute('status') === Status::FAILED) {
|
||||
$queueForUsage
|
||||
->addMetric(METRIC_BUILDS_FAILED, 1) // per project
|
||||
->addMetric(METRIC_BUILDS_COMPUTE_FAILED, (int)$build->getAttribute('duration', 0) * 1000)
|
||||
@@ -621,16 +622,16 @@ class Builds extends Action
|
||||
|
||||
if (!empty($providerCommitHash)) {
|
||||
$message = match ($status) {
|
||||
'ready' => 'Build succeeded.',
|
||||
'failed' => 'Build failed.',
|
||||
'processing' => 'Building...',
|
||||
Status::READY => 'Build ready.',
|
||||
Status::FAILED => 'Build failed.',
|
||||
Status::BUILDING => 'Building...',
|
||||
default => $status
|
||||
};
|
||||
|
||||
$state = match ($status) {
|
||||
'ready' => 'success',
|
||||
'failed' => 'failure',
|
||||
'processing' => 'pending',
|
||||
Status::READY => 'success.',
|
||||
Status::FAILED => 'failure.',
|
||||
Status::BUILDING => 'pending',
|
||||
default => $status
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use Ahc\Jwt\JWT;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Func;
|
||||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Messaging\Adapter\Realtime;
|
||||
use Appwrite\Utopia\Response\Model\Execution;
|
||||
use Exception;
|
||||
@@ -248,7 +249,7 @@ class Functions extends Action
|
||||
'deploymentInternalId' => '',
|
||||
'deploymentId' => '',
|
||||
'trigger' => $trigger,
|
||||
'status' => 'failed',
|
||||
'status' => Status::FAILED,
|
||||
'responseStatusCode' => 0,
|
||||
'responseHeaders' => [],
|
||||
'requestPath' => $path,
|
||||
@@ -345,7 +346,7 @@ class Functions extends Action
|
||||
return;
|
||||
}
|
||||
|
||||
if ($build->getAttribute('status') !== 'ready') {
|
||||
if ($build->getAttribute('status') !== Status::READY) {
|
||||
$errorMessage = 'The execution could not be completed because the build is not ready. Please wait for the build to complete and try again.';
|
||||
$this->fail($errorMessage, $dbForProject, $function, $trigger, $path, $method, $user, $jwt, $event);
|
||||
return;
|
||||
@@ -396,7 +397,7 @@ class Functions extends Action
|
||||
'deploymentInternalId' => $deployment->getInternalId(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'trigger' => $trigger,
|
||||
'status' => 'processing',
|
||||
'status' => Status::EXECUTING,
|
||||
'responseStatusCode' => 0,
|
||||
'responseHeaders' => [],
|
||||
'requestPath' => $path,
|
||||
@@ -417,8 +418,8 @@ class Functions extends Action
|
||||
}
|
||||
}
|
||||
|
||||
if ($execution->getAttribute('status') !== 'processing') {
|
||||
$execution->setAttribute('status', 'processing');
|
||||
if ($execution->getAttribute('status') !== Status::EXECUTING) {
|
||||
$execution->setAttribute('status', Status::EXECUTING);
|
||||
|
||||
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
|
||||
}
|
||||
@@ -494,7 +495,7 @@ class Functions extends Action
|
||||
logging: $function->getAttribute('logging', true),
|
||||
);
|
||||
|
||||
$status = $executionResponse['statusCode'] >= 400 ? 'failed' : 'completed';
|
||||
$status = $executionResponse['statusCode'] >= 400 ? Status::FAILED : Status::SUCCESSFUL;
|
||||
|
||||
$headersFiltered = [];
|
||||
foreach ($executionResponse['headers'] as $key => $value) {
|
||||
@@ -515,7 +516,7 @@ class Functions extends Action
|
||||
$durationEnd = \microtime(true);
|
||||
$execution
|
||||
->setAttribute('duration', $durationEnd - $durationStart)
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('status', Status::FAILED)
|
||||
->setAttribute('responseStatusCode', 500)
|
||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Messaging\Status;
|
||||
use Appwrite\Functions\Status as FunctionsStatus;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
@@ -22,16 +24,12 @@ class Build extends Model
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
// Build Status
|
||||
// Failed - The deployment build has failed. More details can usually be found in buildStderr
|
||||
// Ready - The deployment build was successful and the deployment is ready to be deployed
|
||||
// Processing - The deployment is currently waiting to have a build triggered
|
||||
// Building - The deployment is currently being built
|
||||
/** Build Status check \Appwrite\Functions\Status */
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built',
|
||||
'default' => '',
|
||||
'example' => 'ready',
|
||||
'example' => FunctionsStatus::READY,
|
||||
])
|
||||
->addRule('stdout', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
@@ -72,9 +73,9 @@ class Deployment extends Model
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed".',
|
||||
'description' => 'The deployment status. Possible values are "' . Status::QUEUED . '","' . Status::BUILDING . '","' . Status::READY . '","' . Status::FAILED . '", and "' . Status::CANCELLED . '".',
|
||||
'default' => '',
|
||||
'example' => 'ready',
|
||||
'example' => Status::READY,
|
||||
])
|
||||
->addRule('buildLogs', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Database\DateTime;
|
||||
@@ -51,9 +52,9 @@ class Execution extends Model
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`.',
|
||||
'description' => 'The status of the function execution. Possible values can be: `'.Status::QUEUED.'`,`'.Status::EXECUTING.'`,`'.Status::SUCCESSFUL.'`,`'.Status::CANCELLED.'`, or `'.Status::FAILED.'`.',
|
||||
'default' => '',
|
||||
'example' => 'processing',
|
||||
'example' => Status::EXECUTING,
|
||||
])
|
||||
->addRule('requestMethod', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Vcs;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\System\System;
|
||||
|
||||
@@ -76,9 +77,9 @@ class Comment
|
||||
$hostname = System::getEnv('_APP_DOMAIN');
|
||||
|
||||
foreach ($project['functions'] as $functionId => $function) {
|
||||
if ($function['status'] === 'waiting' || $function['status'] === 'processing' || $function['status'] === 'building') {
|
||||
if ($function['status'] == Status::QUEUED || $function['status'] === Status::BUILDING) {
|
||||
$text .= "**Your function deployment is in progress. Please check back in a few minutes for the updated status.**\n\n";
|
||||
} elseif ($function['status'] === 'ready') {
|
||||
} elseif ($function['status'] === Status::READY) {
|
||||
$text .= "**Your function has been successfully deployed.**\n\n";
|
||||
} else {
|
||||
$text .= "**Your function deployment has failed. Please check the logs for more details and retry.**\n\n";
|
||||
@@ -89,7 +90,7 @@ class Comment
|
||||
$text .= "| :- | :- | :- | :- |\n";
|
||||
|
||||
$generateImage = function (string $status) use ($protocol, $hostname) {
|
||||
$extention = $status === 'building' ? 'gif' : 'png';
|
||||
$extention = $status === Status::BUILDING ? 'gif' : 'png';
|
||||
$imagesUrl = $protocol . '://' . $hostname . '/images/vcs/';
|
||||
$imageUrl = '<picture><source media="(prefers-color-scheme: dark)" srcset="' . $imagesUrl . 'status-' . $status . '-dark.' . $extention . '"><img alt="' . $status . '" height="25" align="center" src="' . $imagesUrl . 'status-' . $status . '-light.' . $extention . '"></picture>';
|
||||
|
||||
@@ -97,11 +98,10 @@ class Comment
|
||||
};
|
||||
|
||||
$status = match ($function['status']) {
|
||||
'waiting' => $generateImage('waiting') . ' Waiting to build',
|
||||
'processing' => $generateImage('processing') . ' Processing',
|
||||
'building' => $generateImage('building') . ' Building',
|
||||
'ready' => $generateImage('ready') . ' Ready',
|
||||
'failed' => $generateImage('failed') . ' Failed',
|
||||
Status::QUEUED => $generateImage(Status::QUEUED) . ' Queued',
|
||||
Status::BUILDING => $generateImage(Status::BUILDING) . ' Building',
|
||||
Status::READY => $generateImage(Status::READY) . ' Ready',
|
||||
Status::FAILED => $generateImage(Status::FAILED) . ' Failed',
|
||||
};
|
||||
|
||||
if ($function['action']['type'] === 'logs') {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\General;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use DateTime;
|
||||
@@ -686,9 +687,9 @@ class UsageTest extends Scope
|
||||
|
||||
$executionTime += (int) ($response['body']['duration'] * 1000);
|
||||
|
||||
if ($response['body']['status'] == 'failed') {
|
||||
if ($response['body']['status'] == Status::FAILED) {
|
||||
$failures += 1;
|
||||
} elseif ($response['body']['status'] == 'completed') {
|
||||
} elseif ($response['body']['status'] == Status::SUCCESSFUL) {
|
||||
$executions += 1;
|
||||
}
|
||||
|
||||
@@ -708,9 +709,9 @@ class UsageTest extends Scope
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEquals($functionId, $response['body']['functionId']);
|
||||
|
||||
if ($response['body']['status'] == 'failed') {
|
||||
if ($response['body']['status'] == Status::FAILED) {
|
||||
$failures += 1;
|
||||
} elseif ($response['body']['status'] == 'completed') {
|
||||
} elseif ($response['body']['status'] == Status::SUCCESSFUL) {
|
||||
$executions += 1;
|
||||
}
|
||||
$executionTime += (int) ($response['body']['duration'] * 1000);
|
||||
@@ -741,9 +742,9 @@ class UsageTest extends Scope
|
||||
], $this->getHeaders()),
|
||||
);
|
||||
|
||||
if ($response['body']['status'] == 'failed') {
|
||||
if ($response['body']['status'] == Status::FAILED) {
|
||||
$failures += 1;
|
||||
} elseif ($response['body']['status'] == 'completed') {
|
||||
} elseif ($response['body']['status'] == Status::SUCCESSFUL) {
|
||||
$executions += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\Functions;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\CLI\Console;
|
||||
|
||||
@@ -26,7 +27,7 @@ trait FunctionsBase
|
||||
|
||||
if (
|
||||
$deployment['headers']['status-code'] >= 400
|
||||
|| \in_array($deployment['body']['status'], ['ready', 'failed'])
|
||||
|| \in_array($deployment['body']['status'], [Status::READY, Status::FAILED])
|
||||
) {
|
||||
break;
|
||||
}
|
||||
@@ -36,7 +37,7 @@ trait FunctionsBase
|
||||
|
||||
if($checkForSuccess) {
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
|
||||
$this->assertEquals(Status::READY, $deployment['body']['status'], \json_encode($deployment['body']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\Functions;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
@@ -162,7 +163,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
$this->assertCount(2, $executions['body']['executions']);
|
||||
$this->assertIsArray($executions['body']['executions']);
|
||||
$this->assertEquals($executions['body']['executions'][1]['trigger'], 'schedule');
|
||||
$this->assertEquals($executions['body']['executions'][1]['status'], 'completed');
|
||||
$this->assertEquals($executions['body']['executions'][1]['status'], Status::SUCCESSFUL);
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseStatusCode'], 200);
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseBody'], '');
|
||||
$this->assertEquals($executions['body']['executions'][1]['logs'], '');
|
||||
@@ -252,7 +253,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
||||
$this->assertEquals('scheduled', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SCHEDULED, $execution['body']['status']);
|
||||
$this->assertEquals($futureTimeIso, $execution['body']['scheduledAt']);
|
||||
|
||||
$executionId = $execution['body']['$id'];
|
||||
@@ -280,7 +281,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $execution['headers']['status-code']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals('/custom', $execution['body']['requestPath']);
|
||||
$this->assertEquals('GET', $execution['body']['requestMethod']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
@@ -405,7 +406,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||
$this->assertEquals('Test', $output['APPWRITE_FUNCTION_NAME']);
|
||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
||||
@@ -570,8 +571,8 @@ class FunctionsCustomClientTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $base['headers']['status-code']);
|
||||
$this->assertCount(3, $base['body']['executions']);
|
||||
$this->assertEquals('completed', $base['body']['executions'][0]['status']);
|
||||
$this->assertEquals('completed', $base['body']['executions'][1]['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $base['body']['executions'][0]['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $base['body']['executions'][1]['status']);
|
||||
|
||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -605,7 +606,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
'x-appwrite-key' => $apikey,
|
||||
], [
|
||||
'queries' => [
|
||||
Query::equal('status', ['completed'])->toString(),
|
||||
Query::equal('status', [Status::SUCCESSFUL])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -618,7 +619,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
'x-appwrite-key' => $apikey,
|
||||
], [
|
||||
'queries' => [
|
||||
Query::equal('status', ['failed'])->toString(),
|
||||
Query::equal('status', [Status::FAILED])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -754,7 +755,7 @@ class FunctionsCustomClientTest extends Scope
|
||||
|
||||
$output = json_decode($execution['body']['responseBody'], true);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||
$this->assertEquals('Test', $output['APPWRITE_FUNCTION_NAME']);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\Functions;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
@@ -505,7 +506,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
if (
|
||||
$deployment['headers']['status-code'] >= 400
|
||||
|| $deployment['body']['status'] === 'building'
|
||||
|| $deployment['body']['status'] === Status::BUILDING
|
||||
) {
|
||||
break;
|
||||
}
|
||||
@@ -788,7 +789,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertNotEmpty($execution['body']['functionId']);
|
||||
$this->assertEquals(true, (new DatetimeValidator())->isValid($execution['body']['$createdAt']));
|
||||
$this->assertEquals($data['functionId'], $execution['body']['functionId']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertStringContainsString($execution['body']['functionId'], $execution['body']['responseBody']);
|
||||
$this->assertStringContainsString($data['deploymentId'], $execution['body']['responseBody']);
|
||||
@@ -910,7 +911,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertStringContainsString('Test1', $execution['body']['responseBody']);
|
||||
$this->assertStringContainsString('http', $execution['body']['responseBody']);
|
||||
@@ -1156,7 +1157,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertCount(1, $executions['body']['executions']);
|
||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||
$this->assertEquals($executions['body']['executions'][0]['status'], 'failed');
|
||||
$this->assertEquals($executions['body']['executions'][0]['status'], Status::FAILED);
|
||||
$this->assertEquals($executions['body']['executions'][0]['responseStatusCode'], 500);
|
||||
$this->assertGreaterThan(2, $executions['body']['executions'][0]['duration']);
|
||||
$this->assertLessThan(20, $executions['body']['executions'][0]['duration']);
|
||||
@@ -1276,7 +1277,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$output = json_decode($execution['body']['responseBody'], true);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
||||
@@ -1384,7 +1385,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$output = json_decode($execution['body']['responseBody'], true);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertEquals(true, $output['v2Woks']);
|
||||
|
||||
@@ -1492,7 +1493,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$execution = $executions['body']['executions'][0];
|
||||
|
||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['status']);
|
||||
$this->assertEquals(204, $execution['responseStatusCode']);
|
||||
$this->assertStringContainsString($userId, $execution['logs']);
|
||||
$this->assertStringContainsString('Event User', $execution['logs']);
|
||||
@@ -1571,7 +1572,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertNotEmpty($execution['body']['responseBody']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
@@ -1644,7 +1645,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(Status::SUCCESSFUL, $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertEquals($cookie, $execution['body']['responseBody']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\GraphQL;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
@@ -137,8 +138,8 @@ class FunctionsClientTest extends Scope
|
||||
$deployment = $deployment['body']['data']['functionsGetDeployment'];
|
||||
|
||||
if (
|
||||
$deployment['status'] === 'ready'
|
||||
|| $deployment['status'] === 'failed'
|
||||
$deployment['status'] === Status::READY
|
||||
|| $deployment['status'] === Status::FAILED
|
||||
) {
|
||||
break;
|
||||
}
|
||||
@@ -146,7 +147,7 @@ class FunctionsClientTest extends Scope
|
||||
\sleep(1);
|
||||
}
|
||||
|
||||
$this->assertEquals('ready', $deployment['status']);
|
||||
$this->assertEquals(Status::READY, $deployment['status']);
|
||||
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\GraphQL;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
@@ -134,8 +135,8 @@ class FunctionsServerTest extends Scope
|
||||
$deployment = $deployment['body']['data']['functionsGetDeployment'];
|
||||
|
||||
if (
|
||||
$deployment['status'] === 'ready'
|
||||
|| $deployment['status'] === 'failed'
|
||||
$deployment['status'] === Status::READY
|
||||
|| $deployment['status'] === Status::FAILED
|
||||
) {
|
||||
break;
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class FunctionsServerTest extends Scope
|
||||
\sleep(1);
|
||||
}
|
||||
|
||||
$this->assertEquals('ready', $deployment['status']);
|
||||
$this->assertEquals(Status::READY, $deployment['status']);
|
||||
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\Realtime;
|
||||
|
||||
use Appwrite\Functions\Status;
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
@@ -1303,7 +1304,7 @@ class RealtimeCustomClientTest extends Scope
|
||||
|
||||
if (
|
||||
$deployment['headers']['status-code'] >= 400
|
||||
|| \in_array($deployment['body']['status'], ['ready', 'failed'])
|
||||
|| \in_array($deployment['body']['status'], [Status::READY, Status::FAILED])
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user