Merge pull request #2833 from appwrite/fix-review-comments
feat: review comments
This commit is contained in:
commit
7c670dc910
|
@ -942,7 +942,6 @@ App::post('/v1/functions/:functionId/executions')
|
|||
try {
|
||||
$executionResponse = $executor->createExecution(
|
||||
projectId: $project->getId(),
|
||||
functionId: $function->getId(),
|
||||
deploymentId: $deployment->getId(),
|
||||
path: $build->getAttribute('outputPath', ''),
|
||||
vars: $vars,
|
||||
|
@ -967,11 +966,10 @@ App::post('/v1/functions/:functionId/executions')
|
|||
}
|
||||
|
||||
Authorization::skip(fn() => $dbForProject->updateDocument('executions', $executionId, $execution));
|
||||
$executionResponse['response'] = ($executionResponse['status'] !== 'completed') ? $executionResponse['stderr'] : $executionResponse['stdout'];
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic(new Document($executionResponse), Response::MODEL_SYNC_EXECUTION);
|
||||
->dynamic($execution, Response::MODEL_EXECUTION);
|
||||
});
|
||||
|
||||
App::get('/v1/functions/:functionId/executions')
|
||||
|
|
|
@ -395,17 +395,13 @@ App::delete('/v1/runtimes/:runtimeId')
|
|||
App::post('/v1/execution')
|
||||
->desc('Create an execution')
|
||||
->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('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('baseImage', '', new Text(128), 'Base image name of the runtime', false)
|
||||
->inject('activeRuntimes')
|
||||
->inject('response')
|
||||
->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)) {
|
||||
throw new Exception('Runtime not found. Please create the runtime.', 404);
|
||||
|
|
|
@ -114,7 +114,6 @@ class BuildsV1 extends Worker
|
|||
try {
|
||||
$response = $this->executor->createRuntime(
|
||||
projectId: $projectId,
|
||||
functionId: $functionId,
|
||||
deploymentId: $deploymentId,
|
||||
entrypoint: $deployment->getAttribute('entrypoint'),
|
||||
source: $source,
|
||||
|
|
|
@ -290,7 +290,6 @@ class FunctionsV1 extends Worker
|
|||
try {
|
||||
$executionResponse = $this->executor->createExecution(
|
||||
projectId: $projectId,
|
||||
functionId: $functionId,
|
||||
deploymentId: $deploymentId,
|
||||
path: $build->getAttribute('outputPath', ''),
|
||||
vars: $vars,
|
||||
|
|
|
@ -31,7 +31,6 @@ use Appwrite\Utopia\Response\Model\Domain;
|
|||
use Appwrite\Utopia\Response\Model\Error;
|
||||
use Appwrite\Utopia\Response\Model\ErrorDev;
|
||||
use Appwrite\Utopia\Response\Model\Execution;
|
||||
use Appwrite\Utopia\Response\Model\SyncExecution;
|
||||
use Appwrite\Utopia\Response\Model\Build;
|
||||
use Appwrite\Utopia\Response\Model\File;
|
||||
use Appwrite\Utopia\Response\Model\Bucket;
|
||||
|
@ -156,7 +155,6 @@ class Response extends SwooleResponse
|
|||
const MODEL_DEPLOYMENT = 'deployment';
|
||||
const MODEL_DEPLOYMENT_LIST = 'deploymentList';
|
||||
const MODEL_EXECUTION = 'execution';
|
||||
const MODEL_SYNC_EXECUTION = 'syncExecution';
|
||||
const MODEL_EXECUTION_LIST = 'executionList';
|
||||
const MODEL_BUILD = 'build';
|
||||
const MODEL_BUILD_LIST = 'buildList';
|
||||
|
@ -268,7 +266,6 @@ class Response extends SwooleResponse
|
|||
->setModel(new Runtime())
|
||||
->setModel(new Deployment())
|
||||
->setModel(new Execution())
|
||||
->setModel(new SyncExecution())
|
||||
->setModel(new Build())
|
||||
->setModel(new Project())
|
||||
->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
|
||||
*
|
||||
* @param string $functionId
|
||||
* @param string $deploymentId
|
||||
* @param string $projectId
|
||||
* @param string $source
|
||||
|
@ -51,7 +50,6 @@ class Executor
|
|||
* @param array $commands
|
||||
*/
|
||||
public function createRuntime(
|
||||
string $functionId,
|
||||
string $deploymentId,
|
||||
string $projectId,
|
||||
string $source,
|
||||
|
@ -127,7 +125,6 @@ class Executor
|
|||
* Create an execution
|
||||
*
|
||||
* @param string $projectId
|
||||
* @param string $functionId
|
||||
* @param string $deploymentId
|
||||
* @param string $path
|
||||
* @param array $vars
|
||||
|
@ -141,7 +138,6 @@ class Executor
|
|||
*/
|
||||
public function createExecution(
|
||||
string $projectId,
|
||||
string $functionId,
|
||||
string $deploymentId,
|
||||
string $path,
|
||||
array $vars,
|
||||
|
@ -158,13 +154,9 @@ class Executor
|
|||
];
|
||||
$params = [
|
||||
'runtimeId' => "$projectId-$deploymentId",
|
||||
'path' => $path,
|
||||
'vars' => $vars,
|
||||
'data' => $data,
|
||||
'runtime' => $runtime,
|
||||
'entrypoint' => $entrypoint,
|
||||
'timeout' => $timeout,
|
||||
'baseImage' => $baseImage,
|
||||
];
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
||||
|
@ -175,7 +167,6 @@ class Executor
|
|||
switch ($status) {
|
||||
case 404:
|
||||
$response = $this->createRuntime(
|
||||
functionId: $functionId,
|
||||
deploymentId: $deploymentId,
|
||||
projectId: $projectId,
|
||||
source: $path,
|
||||
|
|
|
@ -383,7 +383,7 @@ class FunctionsCustomClientTest extends Scope
|
|||
'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('completed', $execution['body']['status']);
|
||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||
|
|
|
@ -594,12 +594,12 @@ class FunctionsCustomServerTest extends Scope
|
|||
]);
|
||||
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertStringContainsString($data['deploymentId'], $execution['body']['response']);
|
||||
$this->assertStringContainsString('Test1', $execution['body']['response']);
|
||||
$this->assertStringContainsString('http', $execution['body']['response']);
|
||||
$this->assertStringContainsString('PHP', $execution['body']['response']);
|
||||
$this->assertStringContainsString('8.0', $execution['body']['response']);
|
||||
// $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars
|
||||
$this->assertStringContainsString($data['deploymentId'], $execution['body']['stdout']);
|
||||
$this->assertStringContainsString('Test1', $execution['body']['stdout']);
|
||||
$this->assertStringContainsString('http', $execution['body']['stdout']);
|
||||
$this->assertStringContainsString('PHP', $execution['body']['stdout']);
|
||||
$this->assertStringContainsString('8.0', $execution['body']['stdout']);
|
||||
// $this->assertStringContainsString('êä', $execution['body']['sdtout']); // tests unknown utf-8 chars
|
||||
$this->assertLessThan(0.500, $execution['body']['time']);
|
||||
|
||||
return $data;
|
||||
|
|
Loading…
Reference in a new issue