Add Function Specs API

This commit is contained in:
Bradley Schofield
2024-06-12 14:20:10 +09:00
parent f92d5ed93b
commit 2dffddf161
9 changed files with 78 additions and 8 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+20 -2
View File
@@ -455,6 +455,26 @@ App::get('/v1/functions/runtimes')
]), Response::MODEL_RUNTIME_LIST);
});
App::get('/v1/functions/specs')
->groups(['api', 'functions'])
->desc('Get available function specs')
->label('scope', 'functions.read')
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
->label('sdk.namespace', 'functions')
->label('sdk.method', 'getSpecs')
->label('sdk.description', '/docs/references/functions/get-specs.md')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_SPECS)
->inject('response')
->inject('plan')
->action(function (Response $response, array $plan) use ($filterBelowThreshold) {
$response->dynamic(new Document([
'memory' => empty($plan['memoryLimit']) ? $filterBelowThreshold(MEMORY_VALUES, System::getEnv('_APP_FUNCTIONS_MEMORY')) : $filterBelowThreshold(MEMORY_VALUES, $plan['memoryLimit']),
'cpus' => empty($plan['cpuLimit']) ? $filterBelowThreshold(CPU_VALUES, System::getEnv('_APP_FUNCTIONS_CPUS')) : $filterBelowThreshold(CPU_VALUES, $plan['cpuLimit']),
]), Response::MODEL_SPECS);
});
App::get('/v1/functions/:functionId')
->groups(['api', 'functions'])
->desc('Get function')
@@ -712,8 +732,6 @@ App::put('/v1/functions/:functionId')
->inject('gitHub')
->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, int $memory, int $cpus, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) {
// TODO: If only branch changes, re-deploy
var_dump($memory);
var_dump($cpus);
$function = $dbForProject->getDocument('functions', $functionId);
+3
View File
@@ -82,6 +82,7 @@ use Appwrite\Utopia\Response\Model\ProviderRepository;
use Appwrite\Utopia\Response\Model\Rule;
use Appwrite\Utopia\Response\Model\Runtime;
use Appwrite\Utopia\Response\Model\Session;
use Appwrite\Utopia\Response\Model\Specs;
use Appwrite\Utopia\Response\Model\Subscriber;
use Appwrite\Utopia\Response\Model\Target;
use Appwrite\Utopia\Response\Model\Team;
@@ -247,6 +248,7 @@ class Response extends SwooleResponse
public const MODEL_BUILD_LIST = 'buildList'; // Not used anywhere yet
public const MODEL_FUNC_PERMISSIONS = 'funcPermissions';
public const MODEL_HEADERS = 'headers';
public const MODEL_SPECS = 'specs';
// Proxy
public const MODEL_PROXY_RULE = 'proxyRule';
@@ -411,6 +413,7 @@ class Response extends SwooleResponse
->setModel(new Deployment())
->setModel(new Execution())
->setModel(new Build())
->setModel(new Specs())
->setModel(new Project())
->setModel(new Webhook())
->setModel(new Key())
@@ -0,0 +1,49 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Specs extends Model
{
public function __construct()
{
$this
->addRule('cpus', [
'type' => self::TYPE_STRING,
'description' => 'Amount of CPU cores available.',
'default' => '',
'example' => [1, 2, 4, 8],
'array' => true,
])
->addRule('memory', [
'type' => self::TYPE_STRING,
'description' => 'Amount of memory available in MB.',
'default' => '',
'example' => [512, 1024, 2048, 4096, 8192, 16384],
'array' => true,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName(): string
{
return 'Specs';
}
/**
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_SPECS;
}
}