chore: refactor code
This commit is contained in:
parent
41ae96ea77
commit
1307f73c31
|
@ -1721,13 +1721,6 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
$execution->setAttribute('logs', $executionResponse['logs']);
|
$execution->setAttribute('logs', $executionResponse['logs']);
|
||||||
$execution->setAttribute('errors', $executionResponse['errors']);
|
$execution->setAttribute('errors', $executionResponse['errors']);
|
||||||
$execution->setAttribute('duration', $executionResponse['duration']);
|
$execution->setAttribute('duration', $executionResponse['duration']);
|
||||||
|
|
||||||
$queueForUsage
|
|
||||||
->addMetric(METRIC_EXECUTIONS, 1)
|
|
||||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1)
|
|
||||||
->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
|
|
||||||
;
|
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
$durationEnd = \microtime(true);
|
$durationEnd = \microtime(true);
|
||||||
|
|
||||||
|
@ -1737,13 +1730,12 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
->setAttribute('responseStatusCode', 500)
|
->setAttribute('responseStatusCode', 500)
|
||||||
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
|
||||||
Console::error($th->getMessage());
|
Console::error($th->getMessage());
|
||||||
|
} finally {
|
||||||
$queueForUsage
|
$queueForUsage
|
||||||
->addMetric(METRIC_EXECUTIONS, 1)
|
->addMetric(METRIC_EXECUTIONS, 1)
|
||||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1)
|
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1)
|
||||||
->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
|
||||||
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1752,10 +1744,6 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
|
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$roles = Authorization::getRoles();
|
$roles = Authorization::getRoles();
|
||||||
$isPrivilegedUser = Auth::isPrivilegedUser($roles);
|
$isPrivilegedUser = Auth::isPrivilegedUser($roles);
|
||||||
$isAppUser = Auth::isAppUser($roles);
|
$isAppUser = Auth::isAppUser($roles);
|
||||||
|
|
|
@ -412,16 +412,6 @@ class Functions extends Action
|
||||||
->setAttribute('logs', $executionResponse['logs'])
|
->setAttribute('logs', $executionResponse['logs'])
|
||||||
->setAttribute('errors', $executionResponse['errors'])
|
->setAttribute('errors', $executionResponse['errors'])
|
||||||
->setAttribute('duration', $executionResponse['duration']);
|
->setAttribute('duration', $executionResponse['duration']);
|
||||||
|
|
||||||
/** Trigger usage queue */
|
|
||||||
$queueForUsage
|
|
||||||
->setProject($project)
|
|
||||||
->addMetric(METRIC_EXECUTIONS, 1)
|
|
||||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1)
|
|
||||||
->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))
|
|
||||||
->trigger()
|
|
||||||
;
|
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
$durationEnd = \microtime(true);
|
$durationEnd = \microtime(true);
|
||||||
$execution
|
$execution
|
||||||
|
@ -432,6 +422,7 @@ class Functions extends Action
|
||||||
|
|
||||||
$error = $th->getMessage();
|
$error = $th->getMessage();
|
||||||
$errorCode = $th->getCode();
|
$errorCode = $th->getCode();
|
||||||
|
} finally {
|
||||||
/** Trigger usage queue */
|
/** Trigger usage queue */
|
||||||
$queueForUsage
|
$queueForUsage
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
|
|
Loading…
Reference in a new issue