Merge pull request #2947 from appwrite/feat-use-build-timeout
feat: use build timeout when building runtime
This commit is contained in:
commit
119506429f
6 changed files with 40 additions and 41 deletions
|
@ -997,6 +997,9 @@ App::post('/v1/functions/:functionId/executions')
|
|||
$execution->setAttribute('stderr', $executionResponse['stderr']);
|
||||
$execution->setAttribute('time', $executionResponse['time']);
|
||||
} catch (\Throwable $th) {
|
||||
$endtime = \microtime(true);
|
||||
$time = $endtime - $execution->getAttribute('dateCreated');
|
||||
$execution->setAttribute('time', $time);
|
||||
$execution->setAttribute('status', 'failed');
|
||||
$execution->setAttribute('statusCode', $th->getCode());
|
||||
$execution->setAttribute('stderr', $th->getMessage());
|
||||
|
|
|
@ -244,7 +244,7 @@ App::post('/v1/runtimes')
|
|||
command: $commands,
|
||||
stdout: $stdout,
|
||||
stderr: $stderr,
|
||||
timeout: App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)
|
||||
timeout: App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900)
|
||||
);
|
||||
|
||||
if (!$status) {
|
||||
|
@ -467,45 +467,33 @@ App::post('/v1/execution')
|
|||
|
||||
\curl_close($ch);
|
||||
|
||||
// If timeout error
|
||||
if (in_array($errNo, [CURLE_OPERATION_TIMEDOUT, 110])) {
|
||||
$statusCode = 124;
|
||||
switch (true) {
|
||||
/** No Error. */
|
||||
case $errNo === 0:
|
||||
break;
|
||||
/** Runtime not ready for requests yet. 111 is the swoole error code for Connection Refused - see https://openswoole.com/docs/swoole-error-code */
|
||||
case $errNo === 111:
|
||||
throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $error, 406);
|
||||
/** Any other CURL error */
|
||||
default:
|
||||
throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $error, 500);
|
||||
}
|
||||
|
||||
// 110 is the Swoole error code for timeout, see: https://www.swoole.co.uk/docs/swoole-error-code
|
||||
if ($errNo !== 0 && $errNo !== CURLE_COULDNT_CONNECT && $errNo !== CURLE_OPERATION_TIMEDOUT && $errNo !== 110) {
|
||||
throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $error, 406);
|
||||
|
||||
switch (true) {
|
||||
case $statusCode >= 500:
|
||||
$stderr = $executorResponse ?? 'Internal Runtime error.';
|
||||
break;
|
||||
case $statusCode >= 100:
|
||||
$stdout = $executorResponse;
|
||||
break;
|
||||
default:
|
||||
$stderr = $executorResponse ?? 'Execution failed.';
|
||||
break;
|
||||
}
|
||||
|
||||
$executionData = [];
|
||||
|
||||
if (!empty($executorResponse)) {
|
||||
$executionData = json_decode($executorResponse, true);
|
||||
}
|
||||
|
||||
if (isset($executionData['code'])) {
|
||||
$statusCode = $executionData['code'];
|
||||
}
|
||||
|
||||
if ($statusCode === 500) {
|
||||
if (isset($executionData['message'])) {
|
||||
$stderr = $executionData['message'];
|
||||
} else {
|
||||
$stderr = 'Internal Runtime error';
|
||||
}
|
||||
} else if ($statusCode === 124) {
|
||||
$stderr = 'Execution timed out.';
|
||||
} else if ($statusCode === 0) {
|
||||
$stderr = 'Execution failed.';
|
||||
} else if ($statusCode >= 200 && $statusCode < 300) {
|
||||
$stdout = $executorResponse;
|
||||
} else {
|
||||
$stderr = 'Execution failed.';
|
||||
}
|
||||
|
||||
|
||||
$executionEnd = \microtime(true);
|
||||
$executionTime = ($executionEnd - $executionStart);
|
||||
$functionStatus = ($statusCode >= 200 && $statusCode < 300) ? 'completed' : 'failed';
|
||||
$functionStatus = ($statusCode >= 500) ? 'failed' : 'completed';
|
||||
|
||||
Console::success('Function executed in ' . $executionTime . ' seconds, status: ' . $functionStatus);
|
||||
|
||||
|
|
|
@ -27,6 +27,11 @@ function getConsoleDB(): Database
|
|||
$database = new Database(new MariaDB($register->get('db')), $cache);
|
||||
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
||||
$database->setNamespace('_console'); // Main DB
|
||||
|
||||
if (!$database->exists($database->getDefaultDatabase(), '_metadata')) {
|
||||
throw new \Exception('Console project not ready');
|
||||
}
|
||||
|
||||
break; // leave loop if successful
|
||||
} catch (\Exception $e) {
|
||||
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
||||
|
|
|
@ -295,7 +295,10 @@ class FunctionsV1 extends Worker
|
|||
->setAttribute('stderr', $executionResponse['stderr'])
|
||||
->setAttribute('time', $executionResponse['time']);
|
||||
} catch (\Throwable $th) {
|
||||
$endtime = \microtime(true);
|
||||
$time = $endtime - $execution->getAttribute('dateCreated');
|
||||
$execution
|
||||
->setAttribute('time', $time)
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('statusCode', $th->getCode())
|
||||
->setAttribute('stderr', $th->getMessage());
|
||||
|
|
|
@ -209,7 +209,7 @@ abstract class Worker
|
|||
throw new \Exception("Project does not exist: {$projectId}");
|
||||
}
|
||||
|
||||
if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), 'realtime')) {
|
||||
if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), '_metadata')) {
|
||||
throw new \Exception('Console project not ready');
|
||||
}
|
||||
|
||||
|
|
|
@ -748,7 +748,7 @@ class FunctionsCustomServerTest extends Scope
|
|||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -762,11 +762,11 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||
$this->assertEquals($executions['body']['executions'][0]['status'], 'failed');
|
||||
$this->assertEquals($executions['body']['executions'][0]['statusCode'], 124);
|
||||
$this->assertEquals($executions['body']['executions'][0]['statusCode'], 500);
|
||||
$this->assertGreaterThan(2, $executions['body']['executions'][0]['time']);
|
||||
$this->assertLessThan(3, $executions['body']['executions'][0]['time']);
|
||||
$this->assertLessThan(6, $executions['body']['executions'][0]['time']);
|
||||
$this->assertEquals($executions['body']['executions'][0]['response'], '');
|
||||
$this->assertEquals($executions['body']['executions'][0]['stderr'], 'Execution timed out.');
|
||||
$this->assertEquals($executions['body']['executions'][0]['stderr'], 'An internal curl error has occurred within the executor! Error Msg: Operation timed out');
|
||||
|
||||
// Cleanup : Delete function
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
||||
|
|
Loading…
Reference in a new issue