mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #2833 from appwrite/fix-review-comments
feat: review comments
This commit is contained in:
commit
7c670dc910
9 changed files with 9 additions and 82 deletions
|
|
@ -942,7 +942,6 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
try {
|
try {
|
||||||
$executionResponse = $executor->createExecution(
|
$executionResponse = $executor->createExecution(
|
||||||
projectId: $project->getId(),
|
projectId: $project->getId(),
|
||||||
functionId: $function->getId(),
|
|
||||||
deploymentId: $deployment->getId(),
|
deploymentId: $deployment->getId(),
|
||||||
path: $build->getAttribute('outputPath', ''),
|
path: $build->getAttribute('outputPath', ''),
|
||||||
vars: $vars,
|
vars: $vars,
|
||||||
|
|
@ -967,11 +966,10 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
}
|
}
|
||||||
|
|
||||||
Authorization::skip(fn() => $dbForProject->updateDocument('executions', $executionId, $execution));
|
Authorization::skip(fn() => $dbForProject->updateDocument('executions', $executionId, $execution));
|
||||||
$executionResponse['response'] = ($executionResponse['status'] !== 'completed') ? $executionResponse['stderr'] : $executionResponse['stdout'];
|
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||||
->dynamic(new Document($executionResponse), Response::MODEL_SYNC_EXECUTION);
|
->dynamic($execution, Response::MODEL_EXECUTION);
|
||||||
});
|
});
|
||||||
|
|
||||||
App::get('/v1/functions/:functionId/executions')
|
App::get('/v1/functions/:functionId/executions')
|
||||||
|
|
|
||||||
|
|
@ -395,17 +395,13 @@ App::delete('/v1/runtimes/:runtimeId')
|
||||||
App::post('/v1/execution')
|
App::post('/v1/execution')
|
||||||
->desc('Create an execution')
|
->desc('Create an execution')
|
||||||
->param('runtimeId', '', new Text(64), 'The runtimeID to execute')
|
->param('runtimeId', '', new Text(64), 'The runtimeID to execute')
|
||||||
->param('path', '', new Text(0), 'Path containing the built files.', false)
|
|
||||||
->param('vars', [], new Assoc(), 'Environment variables required for the build', false)
|
->param('vars', [], new Assoc(), 'Environment variables required for the build', false)
|
||||||
->param('data', '', new Text(8192), 'Data to be forwarded to the function, this is user specified.', true)
|
->param('data', '', new Text(8192), 'Data to be forwarded to the function, this is user specified.', true)
|
||||||
->param('runtime', '', new Text(128), 'Runtime for the cloud function', false)
|
|
||||||
->param('entrypoint', '', new Text(256), 'Entrypoint of the code file')
|
|
||||||
->param('timeout', 15, new ValidatorRange(1, 900), 'Function maximum execution time in seconds.', true)
|
->param('timeout', 15, new ValidatorRange(1, 900), 'Function maximum execution time in seconds.', true)
|
||||||
->param('baseImage', '', new Text(128), 'Base image name of the runtime', false)
|
|
||||||
->inject('activeRuntimes')
|
->inject('activeRuntimes')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->action(
|
->action(
|
||||||
function (string $runtimeId, string $path, array $vars, string $data, string $runtime, string $entrypoint, $timeout, string $baseImage, $activeRuntimes, Response $response) {
|
function (string $runtimeId, array $vars, string $data, $timeout, $activeRuntimes, Response $response) {
|
||||||
|
|
||||||
if (!$activeRuntimes->exists($runtimeId)) {
|
if (!$activeRuntimes->exists($runtimeId)) {
|
||||||
throw new Exception('Runtime not found. Please create the runtime.', 404);
|
throw new Exception('Runtime not found. Please create the runtime.', 404);
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,6 @@ class BuildsV1 extends Worker
|
||||||
try {
|
try {
|
||||||
$response = $this->executor->createRuntime(
|
$response = $this->executor->createRuntime(
|
||||||
projectId: $projectId,
|
projectId: $projectId,
|
||||||
functionId: $functionId,
|
|
||||||
deploymentId: $deploymentId,
|
deploymentId: $deploymentId,
|
||||||
entrypoint: $deployment->getAttribute('entrypoint'),
|
entrypoint: $deployment->getAttribute('entrypoint'),
|
||||||
source: $source,
|
source: $source,
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,6 @@ class FunctionsV1 extends Worker
|
||||||
try {
|
try {
|
||||||
$executionResponse = $this->executor->createExecution(
|
$executionResponse = $this->executor->createExecution(
|
||||||
projectId: $projectId,
|
projectId: $projectId,
|
||||||
functionId: $functionId,
|
|
||||||
deploymentId: $deploymentId,
|
deploymentId: $deploymentId,
|
||||||
path: $build->getAttribute('outputPath', ''),
|
path: $build->getAttribute('outputPath', ''),
|
||||||
vars: $vars,
|
vars: $vars,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ use Appwrite\Utopia\Response\Model\Domain;
|
||||||
use Appwrite\Utopia\Response\Model\Error;
|
use Appwrite\Utopia\Response\Model\Error;
|
||||||
use Appwrite\Utopia\Response\Model\ErrorDev;
|
use Appwrite\Utopia\Response\Model\ErrorDev;
|
||||||
use Appwrite\Utopia\Response\Model\Execution;
|
use Appwrite\Utopia\Response\Model\Execution;
|
||||||
use Appwrite\Utopia\Response\Model\SyncExecution;
|
|
||||||
use Appwrite\Utopia\Response\Model\Build;
|
use Appwrite\Utopia\Response\Model\Build;
|
||||||
use Appwrite\Utopia\Response\Model\File;
|
use Appwrite\Utopia\Response\Model\File;
|
||||||
use Appwrite\Utopia\Response\Model\Bucket;
|
use Appwrite\Utopia\Response\Model\Bucket;
|
||||||
|
|
@ -156,7 +155,6 @@ class Response extends SwooleResponse
|
||||||
const MODEL_DEPLOYMENT = 'deployment';
|
const MODEL_DEPLOYMENT = 'deployment';
|
||||||
const MODEL_DEPLOYMENT_LIST = 'deploymentList';
|
const MODEL_DEPLOYMENT_LIST = 'deploymentList';
|
||||||
const MODEL_EXECUTION = 'execution';
|
const MODEL_EXECUTION = 'execution';
|
||||||
const MODEL_SYNC_EXECUTION = 'syncExecution';
|
|
||||||
const MODEL_EXECUTION_LIST = 'executionList';
|
const MODEL_EXECUTION_LIST = 'executionList';
|
||||||
const MODEL_BUILD = 'build';
|
const MODEL_BUILD = 'build';
|
||||||
const MODEL_BUILD_LIST = 'buildList';
|
const MODEL_BUILD_LIST = 'buildList';
|
||||||
|
|
@ -268,7 +266,6 @@ class Response extends SwooleResponse
|
||||||
->setModel(new Runtime())
|
->setModel(new Runtime())
|
||||||
->setModel(new Deployment())
|
->setModel(new Deployment())
|
||||||
->setModel(new Execution())
|
->setModel(new Execution())
|
||||||
->setModel(new SyncExecution())
|
|
||||||
->setModel(new Build())
|
->setModel(new Build())
|
||||||
->setModel(new Project())
|
->setModel(new Project())
|
||||||
->setModel(new Webhook())
|
->setModel(new Webhook())
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Utopia\Response\Model;
|
|
||||||
|
|
||||||
use Appwrite\Utopia\Response;
|
|
||||||
use Appwrite\Utopia\Response\Model;
|
|
||||||
|
|
||||||
class SyncExecution extends Model
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this
|
|
||||||
->addRule('status', [
|
|
||||||
'type' => self::TYPE_STRING,
|
|
||||||
'description' => 'Execution Status.',
|
|
||||||
'default' => '',
|
|
||||||
'example' => 'completed',
|
|
||||||
])
|
|
||||||
->addRule('response', [
|
|
||||||
'type' => self::TYPE_STRING,
|
|
||||||
'description' => 'Execution Response.',
|
|
||||||
'default' => '',
|
|
||||||
'example' => 'Hello World!',
|
|
||||||
])
|
|
||||||
->addRule('time', [
|
|
||||||
'type' => self::TYPE_INTEGER,
|
|
||||||
'description' => 'Execution Time.',
|
|
||||||
'default' => 0,
|
|
||||||
'example' => 100,
|
|
||||||
])
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Name
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName():string
|
|
||||||
{
|
|
||||||
return 'Syncronous Execution';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Collection
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType():string
|
|
||||||
{
|
|
||||||
return Response::MODEL_SYNC_EXECUTION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -36,7 +36,6 @@ class Executor
|
||||||
*
|
*
|
||||||
* Launches a runtime container for a deployment ready for execution
|
* Launches a runtime container for a deployment ready for execution
|
||||||
*
|
*
|
||||||
* @param string $functionId
|
|
||||||
* @param string $deploymentId
|
* @param string $deploymentId
|
||||||
* @param string $projectId
|
* @param string $projectId
|
||||||
* @param string $source
|
* @param string $source
|
||||||
|
|
@ -51,7 +50,6 @@ class Executor
|
||||||
* @param array $commands
|
* @param array $commands
|
||||||
*/
|
*/
|
||||||
public function createRuntime(
|
public function createRuntime(
|
||||||
string $functionId,
|
|
||||||
string $deploymentId,
|
string $deploymentId,
|
||||||
string $projectId,
|
string $projectId,
|
||||||
string $source,
|
string $source,
|
||||||
|
|
@ -127,7 +125,6 @@ class Executor
|
||||||
* Create an execution
|
* Create an execution
|
||||||
*
|
*
|
||||||
* @param string $projectId
|
* @param string $projectId
|
||||||
* @param string $functionId
|
|
||||||
* @param string $deploymentId
|
* @param string $deploymentId
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param array $vars
|
* @param array $vars
|
||||||
|
|
@ -141,7 +138,6 @@ class Executor
|
||||||
*/
|
*/
|
||||||
public function createExecution(
|
public function createExecution(
|
||||||
string $projectId,
|
string $projectId,
|
||||||
string $functionId,
|
|
||||||
string $deploymentId,
|
string $deploymentId,
|
||||||
string $path,
|
string $path,
|
||||||
array $vars,
|
array $vars,
|
||||||
|
|
@ -158,13 +154,9 @@ class Executor
|
||||||
];
|
];
|
||||||
$params = [
|
$params = [
|
||||||
'runtimeId' => "$projectId-$deploymentId",
|
'runtimeId' => "$projectId-$deploymentId",
|
||||||
'path' => $path,
|
|
||||||
'vars' => $vars,
|
'vars' => $vars,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'runtime' => $runtime,
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'timeout' => $timeout,
|
'timeout' => $timeout,
|
||||||
'baseImage' => $baseImage,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
||||||
|
|
@ -175,7 +167,6 @@ class Executor
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case 404:
|
case 404:
|
||||||
$response = $this->createRuntime(
|
$response = $this->createRuntime(
|
||||||
functionId: $functionId,
|
|
||||||
deploymentId: $deploymentId,
|
deploymentId: $deploymentId,
|
||||||
projectId: $projectId,
|
projectId: $projectId,
|
||||||
source: $path,
|
source: $path,
|
||||||
|
|
|
||||||
|
|
@ -383,7 +383,7 @@ class FunctionsCustomClientTest extends Scope
|
||||||
'async' => false
|
'async' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = json_decode($execution['body']['response'], true);
|
$output = json_decode($execution['body']['stdout'], true);
|
||||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||||
$this->assertEquals('completed', $execution['body']['status']);
|
$this->assertEquals('completed', $execution['body']['status']);
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||||
|
|
|
||||||
|
|
@ -594,12 +594,12 @@ class FunctionsCustomServerTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('completed', $execution['body']['status']);
|
$this->assertEquals('completed', $execution['body']['status']);
|
||||||
$this->assertStringContainsString($data['deploymentId'], $execution['body']['response']);
|
$this->assertStringContainsString($data['deploymentId'], $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('Test1', $execution['body']['response']);
|
$this->assertStringContainsString('Test1', $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('http', $execution['body']['response']);
|
$this->assertStringContainsString('http', $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('PHP', $execution['body']['response']);
|
$this->assertStringContainsString('PHP', $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('8.0', $execution['body']['response']);
|
$this->assertStringContainsString('8.0', $execution['body']['stdout']);
|
||||||
// $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars
|
// $this->assertStringContainsString('êä', $execution['body']['sdtout']); // tests unknown utf-8 chars
|
||||||
$this->assertLessThan(0.500, $execution['body']['time']);
|
$this->assertLessThan(0.500, $execution['body']['time']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue