Set hard timeouts for API dbs

This commit is contained in:
Jake Barnby
2023-10-19 15:32:45 +13:00
parent db3fa21468
commit 389d367fca
4 changed files with 19 additions and 5 deletions
+5
View File
@@ -466,6 +466,11 @@ return [
'description' => 'Database already exists',
'code' => 409
],
Exception::DATABASE_TIMEOUT => [
'name' => Exception::DATABASE_TIMEOUT,
'description' => 'Database timed out.',
'code' => 408
],
/** Collections */
Exception::COLLECTION_NOT_FOUND => [
+5 -1
View File
@@ -690,7 +690,11 @@ App::error()
break;
}
} elseif ($error instanceof Utopia\Database\Exception\Conflict) {
$error = new AppwriteException(AppwriteException::DOCUMENT_UPDATE_CONFLICT, null, null, $error);
$error = new AppwriteException(AppwriteException::DOCUMENT_UPDATE_CONFLICT, previous: $error);
$code = $error->getCode();
$message = $error->getMessage();
} elseif ($error instanceof Utopia\Database\Exception\Timeout) {
$error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, $message, previous: $error);
$code = $error->getCode();
$message = $error->getMessage();
}
+8 -4
View File
@@ -1115,11 +1115,13 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole,
$dbAdapter = $pools
->get($project->getAttribute('database'))
->pop()
->getResource()
;
->getResource();
$database = new Database($dbAdapter, $cache);
$database->setNamespace('_' . $project->getInternalId());
$database
->setNamespace('_' . $project->getInternalId())
->setTimeout(milliseconds: 15000);
return $database;
}, ['pools', 'dbForConsole', 'cache', 'project']);
@@ -1133,7 +1135,9 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) {
$database = new Database($dbAdapter, $cache);
$database->setNamespace('_console');
$database
->setNamespace('_console')
->setTimeout(milliseconds: 15000);
return $database;
}, ['pools', 'cache']);
+1
View File
@@ -145,6 +145,7 @@ class Exception extends \Exception
/** Databases */
public const DATABASE_NOT_FOUND = 'database_not_found';
public const DATABASE_ALREADY_EXISTS = 'database_already_exists';
public const DATABASE_TIMEOUT = 'database_timeout';
/** Collections */
public const COLLECTION_NOT_FOUND = 'collection_not_found';