chore: refactor finally clause

This commit is contained in:
loks0n 2024-05-20 22:35:40 +01:00
parent 47ed708293
commit ff1cabdbf7
2 changed files with 8 additions and 14 deletions

View file

@ -1753,9 +1753,6 @@ App::post('/v1/functions/:functionId/executions')
Console::error($th->getMessage()); Console::error($th->getMessage());
if ($th instanceof AppwriteException) { if ($th instanceof AppwriteException) {
if ($function->getAttribute('logging')) {
Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
}
throw $th; throw $th;
} }
} finally { } finally {
@ -1765,11 +1762,11 @@ App::post('/v1/functions/:functionId/executions')
->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function
; ;
}
if ($function->getAttribute('logging')) { if ($function->getAttribute('logging')) {
/** @var Document $execution */ /** @var Document $execution */
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
}
} }
$roles = Authorization::getRoles(); $roles = Authorization::getRoles();

View file

@ -300,9 +300,6 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
Console::error($th->getMessage()); Console::error($th->getMessage());
if ($th instanceof AppwriteException) { if ($th instanceof AppwriteException) {
if ($function->getAttribute('logging')) {
Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
}
throw $th; throw $th;
} }
} finally { } finally {
@ -312,11 +309,11 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project ->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS_COMPUTE), (int)($execution->getAttribute('duration') * 1000)) // per function
; ;
}
if ($function->getAttribute('logging')) { if ($function->getAttribute('logging')) {
/** @var Document $execution */ /** @var Document $execution */
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
}
} }
$execution->setAttribute('logs', ''); $execution->setAttribute('logs', '');