mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
feat: fix timeout issues
This commit is contained in:
+20
-21
@@ -82,7 +82,9 @@ class Executor
|
||||
'commands' => $commands
|
||||
];
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900));
|
||||
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $timeout);
|
||||
|
||||
$status = $response['headers']['status-code'];
|
||||
if ($status >= 400) {
|
||||
@@ -159,13 +161,18 @@ class Executor
|
||||
'timeout' => $timeout,
|
||||
];
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
||||
/* Add 2 seconds as a buffer to the actual timeout value since there can be a slight variance*/
|
||||
$requestTimeout = $timeout + 2;
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
|
||||
$status = $response['headers']['status-code'];
|
||||
|
||||
if ($status >= 400) {
|
||||
for ($attempts = 0; $attempts < 10; $attempts++) {
|
||||
switch ($status) {
|
||||
case 404:
|
||||
for ($attempts = 0; $attempts < 10; $attempts++) {
|
||||
try {
|
||||
switch (true) {
|
||||
case $status < 400:
|
||||
return $response['body'];
|
||||
case $status == 404:
|
||||
$response = $this->createRuntime(
|
||||
deploymentId: $deploymentId,
|
||||
projectId: $projectId,
|
||||
@@ -176,31 +183,23 @@ class Executor
|
||||
entrypoint: $entrypoint,
|
||||
commands: []
|
||||
);
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
|
||||
$status = $response['headers']['status-code'];
|
||||
break;
|
||||
case 406:
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
|
||||
case $status == 406:
|
||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
|
||||
$status = $response['headers']['status-code'];
|
||||
break;
|
||||
default:
|
||||
throw new \Exception($response['body']['message'], $status);
|
||||
}
|
||||
|
||||
if ($status < 400) {
|
||||
return $response['body'];
|
||||
}
|
||||
|
||||
if ($status != 406) {
|
||||
throw new \Exception($response['body']['message'], $status);
|
||||
}
|
||||
|
||||
sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception($e->getMessage(), $e->getCode());
|
||||
}
|
||||
throw new Exception($response['body']['message'], 503);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
return $response['body'];
|
||||
throw new Exception($response['body']['message'], 503);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user