Fix execution status not updating if usage stats trigger fails

Move the execution document update inside the finally block and wrap
it in try-catch to ensure the execution record is always updated,
even if queueForStatsUsage->trigger() throws an exception.
This commit is contained in:
Chirag Aggarwal 2026-01-14 15:57:21 +05:30
parent c12cad80bb
commit 6c866be9f3

View file

@ -462,7 +462,11 @@ class Functions extends Action
if ($execution->getAttribute('status') !== 'processing') {
$execution->setAttribute('status', 'processing');
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
}
}
$durationStart = \microtime(true);
@ -605,6 +609,13 @@ class Functions extends Action
$error = $th->getMessage();
$errorCode = $th->getCode();
} finally {
/** Update execution status */
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
}
/** Trigger usage queue */
$queueForStatsUsage
->setProject($project)
@ -621,8 +632,6 @@ class Functions extends Action
;
}
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
$executionModel = new Execution();
$realtimeExecution = $executionModel->filter(new Document($execution->getArrayCopy()));
$realtimeExecution = $realtimeExecution->getArrayCopy(\array_keys($executionModel->getRules()));