From fba60f974e3efeeaf00eceeee5bf00340dd33bc4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:46:58 +0530 Subject: [PATCH] Throw exception for cancellation if build is already complete --- app/controllers/api/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 1bf51a52b6..8de0887847 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1594,6 +1594,10 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId' throw new Exception(Exception::BUILD_NOT_FOUND); } + if (\in_array($build->getAttribute('status'), ['ready', 'failed'])) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Build is already completed and cannot be cancelled.'); + } + $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('status', 'cancelled')); $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));