Merge pull request #2832 from appwrite/feat-implement-refactor-suggestions
Feat implement refactor suggestions
This commit is contained in:
commit
47ff5cf54d
|
@ -269,6 +269,7 @@ RUN chmod +x /usr/local/bin/doctor && \
|
|||
chmod +x /usr/local/bin/install && \
|
||||
chmod +x /usr/local/bin/migrate && \
|
||||
chmod +x /usr/local/bin/realtime && \
|
||||
chmod +x /usr/local/bin/executor && \
|
||||
chmod +x /usr/local/bin/schedule && \
|
||||
chmod +x /usr/local/bin/sdks && \
|
||||
chmod +x /usr/local/bin/specs && \
|
||||
|
@ -282,8 +283,7 @@ RUN chmod +x /usr/local/bin/doctor && \
|
|||
chmod +x /usr/local/bin/worker-functions && \
|
||||
chmod +x /usr/local/bin/worker-builds && \
|
||||
chmod +x /usr/local/bin/worker-mails && \
|
||||
chmod +x /usr/local/bin/worker-webhooks && \
|
||||
chmod +x /usr/local/bin/executor
|
||||
chmod +x /usr/local/bin/worker-webhooks
|
||||
|
||||
# Letsencrypt Permissions
|
||||
RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -174,16 +174,6 @@ services:
|
|||
- appwrite
|
||||
environment:
|
||||
- _APP_ENV
|
||||
- _APP_OPENSSL_KEY_V1
|
||||
- _APP_REDIS_HOST
|
||||
- _APP_REDIS_PORT
|
||||
- _APP_REDIS_USER
|
||||
- _APP_REDIS_PASS
|
||||
- _APP_DB_HOST
|
||||
- _APP_DB_PORT
|
||||
- _APP_DB_SCHEMA
|
||||
- _APP_DB_USER
|
||||
- _APP_DB_PASS
|
||||
- _APP_FUNCTIONS_TIMEOUT
|
||||
- _APP_FUNCTIONS_BUILD_TIMEOUT
|
||||
- _APP_FUNCTIONS_CONTAINERS
|
||||
|
@ -193,13 +183,11 @@ services:
|
|||
- _APP_FUNCTIONS_MEMORY_SWAP
|
||||
- _APP_EXECUTOR_SECRET
|
||||
- _APP_EXECUTOR_RUNTIME_NETWORK
|
||||
- _APP_USAGE_STATS
|
||||
- _APP_STATSD_HOST
|
||||
- _APP_STATSD_PORT
|
||||
- _APP_LOGGING_PROVIDER
|
||||
- _APP_LOGGING_CONFIG
|
||||
- DOCKERHUB_PULL_USERNAME
|
||||
- DOCKERHUB_PULL_PASSWORD
|
||||
- OPENRUNTIMES_INACTIVE_THRESHOLD
|
||||
|
||||
appwrite-worker-database:
|
||||
image: <?php echo $organization; ?>/<?php echo $image; ?>:<?php echo $version."\n"; ?>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -371,7 +371,7 @@ class DeletesV1 extends Worker
|
|||
$executor = new Executor();
|
||||
foreach ($deploymentIds as $deploymentId) {
|
||||
try {
|
||||
$executor->deleteRuntime($projectId, $functionId, $deploymentId);
|
||||
$executor->deleteRuntime($projectId, $deploymentId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
@ -421,7 +421,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);
|
||||
$executor->deleteRuntime($projectId, $deploymentId);
|
||||
} catch (Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -24,7 +24,7 @@ class Build extends Model
|
|||
])
|
||||
->addRule('deploymentId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The deployment that created this build',
|
||||
'description' => 'The deployment that created this build.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
|
@ -35,7 +35,7 @@ class Build extends Model
|
|||
// Building - The deployment is currently being built
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The build status.',
|
||||
'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',
|
||||
])
|
||||
|
@ -71,17 +71,17 @@ class Build extends Model
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Build';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_BUILD;
|
||||
}
|
||||
|
|
|
@ -122,9 +122,12 @@ class Func extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
* Filter Function
|
||||
*
|
||||
* @return string
|
||||
* Automatically converts a [] default to a stdClass, this is called while grabbing the document.
|
||||
*
|
||||
* @param Document $document
|
||||
* @return Document
|
||||
*/
|
||||
public function filter(Document $document): Document
|
||||
{
|
||||
|
|
|
@ -31,8 +31,25 @@ class Executor
|
|||
$this->endpoint = $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create runtime
|
||||
*
|
||||
* Launches a runtime container for a deployment ready for execution
|
||||
*
|
||||
* @param string $deploymentId
|
||||
* @param string $projectId
|
||||
* @param string $source
|
||||
* @param string $runtime
|
||||
* @param string $baseImage
|
||||
* @param bool $remove
|
||||
* @param string $entrypoint
|
||||
* @param string $workdir
|
||||
* @param string $destinaction
|
||||
* @param string $network
|
||||
* @param array $vars
|
||||
* @param array $commands
|
||||
*/
|
||||
public function createRuntime(
|
||||
string $functionId,
|
||||
string $deploymentId,
|
||||
string $projectId,
|
||||
string $source,
|
||||
|
@ -75,7 +92,15 @@ class Executor
|
|||
return $response['body'];
|
||||
}
|
||||
|
||||
public function deleteRuntime(string $projectId, string $functionId, string $deploymentId)
|
||||
/**
|
||||
* Delete Runtime
|
||||
*
|
||||
* Deletes a runtime and cleans up any containers remaining.
|
||||
*
|
||||
* @param string $projectId
|
||||
* @param string $deploymentId
|
||||
*/
|
||||
public function deleteRuntime(string $projectId, string $deploymentId)
|
||||
{
|
||||
$runtimeId = "$projectId-$deploymentId";
|
||||
$route = "/runtimes/$runtimeId";
|
||||
|
@ -96,9 +121,23 @@ class Executor
|
|||
return $response['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an execution
|
||||
*
|
||||
* @param string $projectId
|
||||
* @param string $deploymentId
|
||||
* @param string $path
|
||||
* @param array $vars
|
||||
* @param string $entrypoint
|
||||
* @param string $data
|
||||
* @param string runtime
|
||||
* @param string $baseImage
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function createExecution(
|
||||
string $projectId,
|
||||
string $functionId,
|
||||
string $deploymentId,
|
||||
string $path,
|
||||
array $vars,
|
||||
|
@ -108,7 +147,6 @@ class Executor
|
|||
string $baseImage,
|
||||
$timeout
|
||||
) {
|
||||
|
||||
$route = "/execution";
|
||||
$headers = [
|
||||
'content-type' => 'application/json',
|
||||
|
@ -116,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);
|
||||
|
@ -133,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