mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
Merge pull request #8152 from appwrite/fix-improve-cold-start-error
fix: improve cold start error
This commit is contained in:
commit
b367e79de2
14 changed files with 79 additions and 53 deletions
|
|
@ -519,6 +519,11 @@ return [
|
|||
'description' => 'Entrypoint for your Appwrite Function is missing. Please specify it when making deployment or update the entrypoint under your function\'s "Settings" > "Configuration" > "Entrypoint".',
|
||||
'code' => 404,
|
||||
],
|
||||
Exception::FUNCTION_SYNCHRONOUS_TIMEOUT => [
|
||||
'name' => Exception::FUNCTION_SYNCHRONOUS_TIMEOUT,
|
||||
'description' => 'Synchronous function execution timed out. Use asynchronous execution instead, or ensure the execution duration doesn\'t exceed 30 seconds.',
|
||||
'code' => 408,
|
||||
],
|
||||
|
||||
/** Builds */
|
||||
Exception::BUILD_NOT_FOUND => [
|
||||
|
|
|
|||
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
|
|
@ -9,6 +9,7 @@ use Appwrite\Event\Func;
|
|||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Event\Validator\FunctionEvent;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Appwrite\Messaging\Adapter\Realtime;
|
||||
use Appwrite\Task\Validator\Cron;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
|
|
@ -1750,6 +1751,13 @@ App::post('/v1/functions/:functionId/executions')
|
|||
->setAttribute('responseStatusCode', 500)
|
||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||
Console::error($th->getMessage());
|
||||
|
||||
if ($th instanceof AppwriteException) {
|
||||
if ($function->getAttribute('logging')) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
|
||||
}
|
||||
throw $th;
|
||||
}
|
||||
} finally {
|
||||
$queueForUsage
|
||||
->addMetric(METRIC_EXECUTIONS, 1)
|
||||
|
|
|
|||
|
|
@ -288,6 +288,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
|||
$execution->setAttribute('logs', $executionResponse['logs']);
|
||||
$execution->setAttribute('errors', $executionResponse['errors']);
|
||||
$execution->setAttribute('duration', $executionResponse['duration']);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$durationEnd = \microtime(true);
|
||||
|
||||
|
|
@ -297,6 +298,13 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
|||
->setAttribute('responseStatusCode', 500)
|
||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||
Console::error($th->getMessage());
|
||||
|
||||
if ($th instanceof AppwriteException) {
|
||||
if ($function->getAttribute('logging')) {
|
||||
Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
|
||||
}
|
||||
throw $th;
|
||||
}
|
||||
} finally {
|
||||
$queueForUsage
|
||||
->addMetric(METRIC_EXECUTIONS, 1)
|
||||
|
|
|
|||
|
|
@ -731,7 +731,7 @@ services:
|
|||
<<: *x-logging
|
||||
restart: unless-stopped
|
||||
stop_signal: SIGINT
|
||||
image: openruntimes/executor:0.4.12
|
||||
image: openruntimes/executor:0.5.5
|
||||
networks:
|
||||
- appwrite
|
||||
- runtimes
|
||||
|
|
|
|||
83
composer.lock
generated
83
composer.lock
generated
|
|
@ -822,16 +822,16 @@
|
|||
},
|
||||
{
|
||||
"name": "paragonie/constant_time_encoding",
|
||||
"version": "v2.6.3",
|
||||
"version": "v2.7.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/paragonie/constant_time_encoding.git",
|
||||
"reference": "58c3f47f650c94ec05a151692652a868995d2938"
|
||||
"reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938",
|
||||
"reference": "58c3f47f650c94ec05a151692652a868995d2938",
|
||||
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/52a0d99e69f56b9ec27ace92ba56897fe6993105",
|
||||
"reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -885,7 +885,7 @@
|
|||
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
|
||||
"source": "https://github.com/paragonie/constant_time_encoding"
|
||||
},
|
||||
"time": "2022-06-14T06:56:20+00:00"
|
||||
"time": "2024-05-08T12:18:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpmailer/phpmailer",
|
||||
|
|
@ -1672,16 +1672,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/dsn",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/dsn.git",
|
||||
"reference": "c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7"
|
||||
"reference": "42ee37a3d1785100b2f69091c9d4affadb6846eb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/dsn/zipball/c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7",
|
||||
"reference": "c11f37a12c3f6aaf9fea97ca7cb363dcc93668d7",
|
||||
"url": "https://api.github.com/repos/utopia-php/dsn/zipball/42ee37a3d1785100b2f69091c9d4affadb6846eb",
|
||||
"reference": "42ee37a3d1785100b2f69091c9d4affadb6846eb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -1713,9 +1713,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/dsn/issues",
|
||||
"source": "https://github.com/utopia-php/dsn/tree/0.2.0"
|
||||
"source": "https://github.com/utopia-php/dsn/tree/0.2.1"
|
||||
},
|
||||
"time": "2023-11-02T12:01:43+00:00"
|
||||
"time": "2024-05-07T02:01:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
|
|
@ -1966,22 +1966,21 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/migration",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/migration.git",
|
||||
"reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657"
|
||||
"reference": "a8a5d392bebf082faf289f4dfe09d9fd76844c33"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/migration/zipball/a72f27bd3dde68752fb185d306c4820e1b8d9657",
|
||||
"reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657",
|
||||
"url": "https://api.github.com/repos/utopia-php/migration/zipball/a8a5d392bebf082faf289f4dfe09d9fd76844c33",
|
||||
"reference": "a8a5d392bebf082faf289f4dfe09d9fd76844c33",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"appwrite/appwrite": "10.1.0",
|
||||
"php": "8.*",
|
||||
"utopia-php/cli": "0.*"
|
||||
"php": "8.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "1.*",
|
||||
|
|
@ -2008,9 +2007,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/migration/issues",
|
||||
"source": "https://github.com/utopia-php/migration/tree/0.4.0"
|
||||
"source": "https://github.com/utopia-php/migration/tree/0.4.4"
|
||||
},
|
||||
"time": "2024-02-25T12:35:21+00:00"
|
||||
"time": "2024-05-17T05:25:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/mongo",
|
||||
|
|
@ -2499,16 +2498,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/vcs",
|
||||
"version": "0.6.5",
|
||||
"version": "0.6.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/vcs.git",
|
||||
"reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2"
|
||||
"reference": "e538264cfee5e3efdfe1771efba04750cf20b2c4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/104e47ea8e38c156ec0e0bd415caa3dcd5046fe2",
|
||||
"reference": "104e47ea8e38c156ec0e0bd415caa3dcd5046fe2",
|
||||
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/e538264cfee5e3efdfe1771efba04750cf20b2c4",
|
||||
"reference": "e538264cfee5e3efdfe1771efba04750cf20b2c4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -2542,9 +2541,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/vcs/issues",
|
||||
"source": "https://github.com/utopia-php/vcs/tree/0.6.5"
|
||||
"source": "https://github.com/utopia-php/vcs/tree/0.6.6"
|
||||
},
|
||||
"time": "2024-01-08T17:11:12+00:00"
|
||||
"time": "2024-05-17T09:36:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/websocket",
|
||||
|
|
@ -2731,16 +2730,16 @@
|
|||
"packages-dev": [
|
||||
{
|
||||
"name": "appwrite/sdk-generator",
|
||||
"version": "0.38.2",
|
||||
"version": "0.38.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/appwrite/sdk-generator.git",
|
||||
"reference": "51284668529e2b10ed933412a42b603c76cded23"
|
||||
"reference": "830a46cc8e34ee096a76d4af6f00adf008a7cbf8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/51284668529e2b10ed933412a42b603c76cded23",
|
||||
"reference": "51284668529e2b10ed933412a42b603c76cded23",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/830a46cc8e34ee096a76d4af6f00adf008a7cbf8",
|
||||
"reference": "830a46cc8e34ee096a76d4af6f00adf008a7cbf8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -2776,9 +2775,9 @@
|
|||
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
|
||||
"support": {
|
||||
"issues": "https://github.com/appwrite/sdk-generator/issues",
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/0.38.2"
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/0.38.5"
|
||||
},
|
||||
"time": "2024-04-25T07:49:29+00:00"
|
||||
"time": "2024-05-17T00:59:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/deprecations",
|
||||
|
|
@ -2899,16 +2898,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.15.2",
|
||||
"version": "v1.15.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134"
|
||||
"reference": "3600b5d17aff52f6100ea4921849deacbbeb8656"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/2c9f8004899815f3f0ee3cb28ef7281e2b589134",
|
||||
"reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/3600b5d17aff52f6100ea4921849deacbbeb8656",
|
||||
"reference": "3600b5d17aff52f6100ea4921849deacbbeb8656",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -2961,7 +2960,7 @@
|
|||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2024-04-23T15:42:34+00:00"
|
||||
"time": "2024-04-30T15:02:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
|
|
@ -3568,16 +3567,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan/phpdoc-parser",
|
||||
"version": "1.28.0",
|
||||
"version": "1.29.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
||||
"reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb"
|
||||
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb",
|
||||
"reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/536889f2b340489d328f5ffb7b02bb6b183ddedc",
|
||||
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -3609,9 +3608,9 @@
|
|||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||
"support": {
|
||||
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0"
|
||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.0"
|
||||
},
|
||||
"time": "2024-04-03T18:51:33+00:00"
|
||||
"time": "2024-05-06T12:04:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
|
|
|
|||
|
|
@ -793,7 +793,7 @@ services:
|
|||
hostname: appwrite-executor
|
||||
<<: *x-logging
|
||||
stop_signal: SIGINT
|
||||
image: openruntimes/executor:0.4.12
|
||||
image: openruntimes/executor:0.5.5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- appwrite
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ class Exception extends \Exception
|
|||
public const FUNCTION_NOT_FOUND = 'function_not_found';
|
||||
public const FUNCTION_RUNTIME_UNSUPPORTED = 'function_runtime_unsupported';
|
||||
public const FUNCTION_ENTRYPOINT_MISSING = 'function_entrypoint_missing';
|
||||
public const FUNCTION_SYNCHRONOUS_TIMEOUT = 'function_synchronous_timeout';
|
||||
|
||||
/** Deployments */
|
||||
public const DEPLOYMENT_NOT_FOUND = 'deployment_not_found';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Executor;
|
||||
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Exception;
|
||||
use Utopia\System\System;
|
||||
|
||||
|
|
@ -193,7 +194,6 @@ class Executor
|
|||
'path' => $path,
|
||||
'method' => $method,
|
||||
'headers' => $headers,
|
||||
|
||||
'image' => $image,
|
||||
'source' => $source,
|
||||
'entrypoint' => $entrypoint,
|
||||
|
|
@ -311,6 +311,8 @@ class Executor
|
|||
|
||||
$responseType = $responseHeaders['content-type'] ?? '';
|
||||
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_errno($ch);
|
||||
$curlErrorMessage = curl_error($ch);
|
||||
|
||||
if ($decode) {
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
|
|
@ -327,8 +329,11 @@ class Executor
|
|||
}
|
||||
}
|
||||
|
||||
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {
|
||||
throw new Exception(curl_error($ch) . ' with status code ' . $responseStatus, $responseStatus);
|
||||
if ($curlError) {
|
||||
if ($curlError == CURLE_OPERATION_TIMEDOUT) {
|
||||
throw new AppwriteException(AppwriteException::FUNCTION_SYNCHRONOUS_TIMEOUT);
|
||||
}
|
||||
throw new Exception($curlErrorMessage . ' with status code ' . $responseStatus, $responseStatus);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
|
|
|||
Loading…
Reference in a new issue