diff --git a/CHANGES.md b/CHANGES.md index be275d3bb5..59a7b09e33 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,9 @@ - _APP_INFLUXDB_HOST - _APP_INFLUXDB_PORT +## Breaking Changes (Read before upgrading!) +- Renamed `env` param on `/v1/functions` to `runtime` (#1314) + ## Bugs - Fixed bug causing runtimes conflict and hanging executions when max Functions containers limit passed (#1288) diff --git a/app/config/collections.php b/app/config/collections.php index 6789237c9c..e6d67f08c3 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1481,8 +1481,8 @@ $collections = [ ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'Env', - 'key' => 'env', + 'label' => 'Runtime', + 'key' => 'runtime', 'type' => Database::SYSTEM_VAR_TYPE_TEXT, 'default' => '', 'required' => false, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0f009aa404..dd58108893 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -39,14 +39,14 @@ App::post('/v1/functions') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') ->param('execute', [], new ArrayList(new Text(64)), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') - ->param('env', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution enviornment.') + ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.') ->param('vars', [], new Assoc(), 'Key-value JSON object.', true) ->param('events', [], new ArrayList(new WhiteList(array_keys(Config::getParam('events')), true)), 'Events list.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) ->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true) ->inject('response') ->inject('projectDB') - ->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) { + ->action(function ($name, $execute, $runtime, $vars, $events, $schedule, $timeout, $response, $projectDB) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ @@ -59,7 +59,7 @@ App::post('/v1/functions') 'dateUpdated' => time(), 'status' => 'disabled', 'name' => $name, - 'env' => $env, + 'runtime' => $runtime, 'tag' => '', 'vars' => $vars, 'events' => $events, diff --git a/app/workers/functions.php b/app/workers/functions.php index e50c2fc68c..5299970e56 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -328,12 +328,12 @@ class FunctionsV1 extends Worker Authorization::reset(); - $runtime = (isset($runtimes[$function->getAttribute('env', '')])) - ? $runtimes[$function->getAttribute('env', '')] + $runtime = (isset($runtimes[$function->getAttribute('runtime', '')])) + ? $runtimes[$function->getAttribute('runtime', '')] : null; if(\is_null($runtime)) { - throw new Exception('Environment "'.$function->getAttribute('env', '').' is not supported'); + throw new Exception('Runtime "'.$function->getAttribute('runtime', '').' is not supported'); } $vars = \array_merge($function->getAttribute('vars', []), [ diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index 94690a9467..6d5bf8c01a 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -47,9 +47,9 @@ class Func extends Model 'default' => '', 'example' => 'enabled', ]) - ->addRule('env', [ + ->addRule('runtime', [ 'type' => self::TYPE_STRING, - 'description' => 'Function execution environment.', + 'description' => 'Function execution runtime.', 'default' => '', 'example' => 'python-3.8', ]) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 12a9edf245..8ba16f8145 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -54,7 +54,7 @@ class FunctionsCustomClientTest extends Scope ], [ 'name' => 'Test', 'execute' => ['user:'.$this->getUser()['$id']], - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', @@ -140,7 +140,7 @@ class FunctionsCustomClientTest extends Scope ], [ 'name' => 'Test', 'execute' => ['*'], - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index edd9081c91..cf0a1cafc4 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -24,7 +24,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'vars' => [ 'funcKey1' => 'funcValue1', 'funcKey2' => 'funcValue2', @@ -43,7 +43,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $response1['headers']['status-code']); $this->assertNotEmpty($response1['body']['$id']); $this->assertEquals('Test', $response1['body']['name']); - $this->assertEquals('php-8.0', $response1['body']['env']); + $this->assertEquals('php-8.0', $response1['body']['runtime']); $this->assertIsInt($response1['body']['dateCreated']); $this->assertIsInt($response1['body']['dateUpdated']); $this->assertEquals('', $response1['body']['tag']); @@ -327,7 +327,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('PHP', $execution['body']['stdout']); $this->assertStringContainsString('8.0', $execution['body']['stdout']); $this->assertEquals('', $execution['body']['stderr']); - $this->assertGreaterThan(0.100, $execution['body']['time']); + $this->assertGreaterThan(0.05, $execution['body']['time']); $this->assertLessThan(0.500, $execution['body']['time']); /** @@ -462,7 +462,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test '.$name, - 'env' => $name, + 'runtime' => $name, 'vars' => [], 'events' => [], 'schedule' => '', @@ -540,7 +540,7 @@ class FunctionsCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test '.$name, - 'env' => $name, + 'runtime' => $name, 'vars' => [], 'events' => [], 'schedule' => '', diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 0ef01ec850..0d3678eaf2 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -306,7 +306,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'execute' => ['*'], 'timeout' => 10, ]); @@ -348,7 +348,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'env' => 'php-8.0', + 'runtime' => 'php-8.0', 'execute' => ['*'], 'vars' => [ 'key1' => 'value1',