mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Improve duration with timeout
This commit is contained in:
@@ -1188,6 +1188,8 @@ App::post('/v1/functions/:functionId/executions')
|
||||
]);
|
||||
|
||||
/** Execute function */
|
||||
$durationStart = \microtime(true);
|
||||
$timeout = $function->getAttribute('timeout', 0);
|
||||
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
|
||||
try {
|
||||
$executionResponse = $executor->createExecution(
|
||||
@@ -1195,7 +1197,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
deploymentId: $deployment->getId(),
|
||||
payload: $data,
|
||||
variables: $vars,
|
||||
timeout: $function->getAttribute('timeout', 0),
|
||||
timeout: $timeout,
|
||||
image: $runtime['image'],
|
||||
source: $build->getAttribute('outputPath', ''),
|
||||
entrypoint: $deployment->getAttribute('entrypoint', ''),
|
||||
@@ -1209,9 +1211,10 @@ App::post('/v1/functions/:functionId/executions')
|
||||
$execution->setAttribute('stderr', $executionResponse['stderr']);
|
||||
$execution->setAttribute('duration', $executionResponse['duration']);
|
||||
} catch (\Throwable $th) {
|
||||
$interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt()));
|
||||
$durationEnd = \microtime(true);
|
||||
$duration = ($durationEnd - $durationStart);
|
||||
$execution
|
||||
->setAttribute('duration', (float)$interval->format('%s.%f'))
|
||||
->setAttribute('duration', \min($duration, $timeout))
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('statusCode', $th->getCode())
|
||||
->setAttribute('stderr', $th->getMessage());
|
||||
|
||||
@@ -125,6 +125,7 @@ Server::setResource('execute', function () {
|
||||
|
||||
/** Execute function */
|
||||
$durationStart = \microtime(true);
|
||||
$timeout = $function->getAttribute('timeout', 0);
|
||||
try {
|
||||
$client = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
|
||||
$executionResponse = $client->createExecution(
|
||||
@@ -132,7 +133,7 @@ Server::setResource('execute', function () {
|
||||
deploymentId: $deploymentId,
|
||||
payload: $vars['APPWRITE_FUNCTION_DATA'] ?? '',
|
||||
variables: $vars,
|
||||
timeout: $function->getAttribute('timeout', 0),
|
||||
timeout: $timeout,
|
||||
image: $runtime['image'],
|
||||
source: $build->getAttribute('outputPath', ''),
|
||||
entrypoint: $deployment->getAttribute('entrypoint', ''),
|
||||
@@ -150,7 +151,7 @@ Server::setResource('execute', function () {
|
||||
$durationEnd = \microtime(true);
|
||||
$duration = ($durationEnd - $durationStart);
|
||||
$execution
|
||||
->setAttribute('duration', $duration)
|
||||
->setAttribute('duration', \min($duration, $timeout))
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('statusCode', $th->getCode())
|
||||
->setAttribute('stderr', $th->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user