From e51295db49f181cb639552f13aa87f383a8b03ba Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 28 Sep 2021 10:09:55 +0100 Subject: [PATCH] Error any execution if the tag is still being built. --- app/executor.php | 21 +++++++++++++++++++-- composer.lock | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/executor.php b/app/executor.php index 0c4fb4300a..33fe9678f6 100644 --- a/app/executor.php +++ b/app/executor.php @@ -680,6 +680,20 @@ function execute(string $trigger, string $projectId, string $executionId, string Authorization::reset(); + if ($tag->getAttribute('status') == 'building') { + Console::error('Execution Failed. Reason: Code was still being built.'); + Authorization::disable(); + $execution = $database->updateDocument(array_merge($execution->getArrayCopy(), [ + 'tagId' => $tag->getId(), + 'status' => 'failed', + 'exitCode' => 1, + 'stderr' => 'Tag is still being built.', // log last 4000 chars output + 'time' => 0 + ])); + Authorization::reset(); + throw new Exception('Tag is still being built.'); + } + // Check if runtime is active $runtime = (isset($runtimes[$function->getAttribute('runtime', '')])) ? $runtimes[$function->getAttribute('runtime', '')] @@ -707,8 +721,6 @@ function execute(string $trigger, string $projectId, string $executionId, string $container = 'appwrite-function-' . $tag->getId(); - // Check if code is built - try { if ($tag->getAttribute('status') !== 'ready') { runBuildStage($tag->getId(), $function, $projectId, $database); @@ -744,6 +756,11 @@ function execute(string $trigger, string $projectId, string $executionId, string 'time' => 0 ])); Authorization::enable(); + return [ + 'status' => 'failed', + 'response' => \utf8_encode(\mb_substr($e->getMessage(), -4000)), // log last 4000 chars output + 'time' => 0 + ]; } $internalFunction = $activeFunctions->get('appwrite-function-' . $tag->getId()); diff --git a/composer.lock b/composer.lock index 5ac2248073..2862fec4e9 100644 --- a/composer.lock +++ b/composer.lock @@ -119,7 +119,7 @@ "source": { "type": "git", "url": "https://github.com/PineappleIOnic/php-runtimes.git", - "reference": "b8814cdb76dbc06f5aafd1a00d6d01573b3ba9c3" + "reference": "35a610b0ae858d514fbfe44bef725a0f83a4f4f3" }, "require": { "php": ">=8.0", @@ -156,7 +156,7 @@ "php", "runtimes" ], - "time": "2021-09-21T09:33:16+00:00" + "time": "2021-09-27T14:18:24+00:00" }, { "name": "chillerlan/php-qrcode",