From 7a465dc8f8dd40c22b8233e7d0c7f047c16988d0 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 2 Jun 2025 17:53:35 +0530 Subject: [PATCH] Don't auto-activate deployment which started earlier & ended later than active deployment --- .../Platform/Modules/Functions/Workers/Builds.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index de5543c9f3..589416be3d 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1072,6 +1072,21 @@ class Builds extends Action /** Set auto deploy */ if ($deployment->getAttribute('activate') === true) { + // Check if current active deployment started later than this deployment + $currentDeploymentId = $resource->getAttribute('deploymentId', ''); + if (!empty($currentDeploymentId)) { + $currentDeployment = $dbForProject->getDocument('deployments', $currentDeploymentId); + if (!$currentDeployment->isEmpty()) { + $currentStartTime = $currentDeployment->getAttribute('buildStartedAt', ''); + $newStartTime = $deployment->getAttribute('buildStartedAt', ''); + + if (!empty($currentStartTime) && !empty($newStartTime) && $currentStartTime > $newStartTime) { + Console::info('Skipping auto-activation as current deployment started later'); + return; + } + } + } + $resource->setAttribute('live', true); switch ($resource->getCollection()) { case 'functions':