From 7a465dc8f8dd40c22b8233e7d0c7f047c16988d0 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Mon, 2 Jun 2025 17:53:35 +0530 Subject: [PATCH 01/13] 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': From 2088792d09383d875f2468b8593fa79341946b50 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 3 Jun 2025 14:23:17 +0530 Subject: [PATCH 02/13] Fix build activation race condition --- composer.lock | 12 ++++----- docker-compose.yml | 2 +- .../Modules/Functions/Workers/Builds.php | 27 +++++++++++++------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/composer.lock b/composer.lock index 9e757f9db8..f27c08954d 100644 --- a/composer.lock +++ b/composer.lock @@ -4807,16 +4807,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.41.0", + "version": "0.41.1", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "96316272a3cee1a3abf5b9f05ae49ebbff03725e" + "reference": "6d9318abf4542a757c87abf056557d6afa1dc06b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/96316272a3cee1a3abf5b9f05ae49ebbff03725e", - "reference": "96316272a3cee1a3abf5b9f05ae49ebbff03725e", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6d9318abf4542a757c87abf056557d6afa1dc06b", + "reference": "6d9318abf4542a757c87abf056557d6afa1dc06b", "shasum": "" }, "require": { @@ -4852,9 +4852,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.41.0" + "source": "https://github.com/appwrite/sdk-generator/tree/0.41.1" }, - "time": "2025-05-26T09:47:45+00:00" + "time": "2025-06-01T04:20:04+00:00" }, { "name": "doctrine/annotations", diff --git a/docker-compose.yml b/docker-compose.yml index 29a43aca91..1861af9afd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -213,7 +213,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.0.32 + image: appwrite/console:6.0.35 restart: unless-stopped networks: - appwrite diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 589416be3d..c933f6cda8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -275,6 +275,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -525,6 +526,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1056,6 +1058,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } @@ -1073,15 +1076,22 @@ 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', ''); + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); + $currentActiveDeploymentId = $resource->getAttribute('deploymentId', ''); + if (!empty($currentActiveDeploymentId)) { + $currentActiveDeployment = $dbForProject->getDocument('deployments', $currentActiveDeploymentId); + if (!$currentActiveDeployment->isEmpty()) { + $currentActiveStartTime = $currentActiveDeployment->getAttribute('buildStartedAt', ''); + $currentActiveEndTime = $currentActiveDeployment->getAttribute('buildEndedAt', ''); + $deploymentStartTime = $deployment->getAttribute('buildStartedAt', ''); + $deploymentEndTime = $deployment->getAttribute('buildEndedAt', ''); - if (!empty($currentStartTime) && !empty($newStartTime) && $currentStartTime > $newStartTime) { - Console::info('Skipping auto-activation as current deployment started later'); + // Skip auto-activation if: + // 1. Current active deployment started later than deployment that is being activated, AND + // 2. Current active deployment finished earlier than deployment that is being activated + if ((!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime > $deploymentStartTime) && + (!empty($currentActiveEndTime) && !empty($deploymentEndTime) && $currentActiveEndTime < $deploymentEndTime)) { + Console::info('Skipping auto-activation as current deployment is more recent'); return; } } @@ -1263,6 +1273,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); } From 995482ee20f2385f4162dd032b682857dedb0148 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 13 Jun 2025 19:04:46 +0530 Subject: [PATCH 03/13] Update console version --- composer.lock | 27 +++++++++++++-------------- docker-compose.yml | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/composer.lock b/composer.lock index e38efa0b96..4e434d714a 100644 --- a/composer.lock +++ b/composer.lock @@ -4807,16 +4807,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.41.0", + "version": "0.41.6", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "96316272a3cee1a3abf5b9f05ae49ebbff03725e" + "reference": "bfcebb968c527e17fdf18d40b8986c83d9c18c93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/96316272a3cee1a3abf5b9f05ae49ebbff03725e", - "reference": "96316272a3cee1a3abf5b9f05ae49ebbff03725e", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/bfcebb968c527e17fdf18d40b8986c83d9c18c93", + "reference": "bfcebb968c527e17fdf18d40b8986c83d9c18c93", "shasum": "" }, "require": { @@ -4852,9 +4852,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.41.0" + "source": "https://github.com/appwrite/sdk-generator/tree/0.41.6" }, - "time": "2025-05-26T09:47:45+00:00" + "time": "2025-06-12T03:27:26+00:00" }, { "name": "doctrine/annotations", @@ -5147,16 +5147,16 @@ }, { "name": "matthiasmullie/minify", - "version": "1.3.73", + "version": "1.3.74", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "cb7a9297b4ab070909cefade30ee95054d4ae87a" + "reference": "a2593286a4135d03c6a6a9e9aeded5d41e931ce4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/cb7a9297b4ab070909cefade30ee95054d4ae87a", - "reference": "cb7a9297b4ab070909cefade30ee95054d4ae87a", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/a2593286a4135d03c6a6a9e9aeded5d41e931ce4", + "reference": "a2593286a4135d03c6a6a9e9aeded5d41e931ce4", "shasum": "" }, "require": { @@ -5167,8 +5167,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": ">=2.0", "matthiasmullie/scrapbook": ">=1.3", - "phpunit/phpunit": ">=4.8", - "squizlabs/php_codesniffer": ">=3.0" + "phpunit/phpunit": ">=4.8" }, "suggest": { "psr/cache-implementation": "Cache implementation to use with Minify::cache" @@ -5206,7 +5205,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.73" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.74" }, "funding": [ { @@ -5214,7 +5213,7 @@ "type": "github" } ], - "time": "2024-03-15T10:27:10+00:00" + "time": "2025-06-12T08:06:04+00:00" }, { "name": "matthiasmullie/path-converter", diff --git a/docker-compose.yml b/docker-compose.yml index c042d36cd5..07870859fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -213,7 +213,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.0.41 + image: appwrite/console:6.1.0 restart: unless-stopped networks: - appwrite From 3ad5a2652ee822cc276c808b49798fc0d471c2ea Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 13 Jun 2025 19:14:00 +0530 Subject: [PATCH 04/13] Update console version --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 07870859fb..a0eeba3ff0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -213,7 +213,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.1.0 + image: appwrite/console:6.0.43 restart: unless-stopped networks: - appwrite From 80c49824821c61623562ab3217c6531d1596f2ba Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 00:51:35 +0530 Subject: [PATCH 05/13] Update only specific attribute --- composer.lock | 12 +- docker-compose.yml | 6 +- .../Modules/Functions/Workers/Builds.php | 124 +++++++++--------- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/composer.lock b/composer.lock index 72b460ec52..653d1841d5 100644 --- a/composer.lock +++ b/composer.lock @@ -5276,16 +5276,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.13.1", + "version": "1.13.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c" + "reference": "faed855a7b5f4d4637717c2b3863e277116beb36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/1720ddd719e16cf0db4eb1c6eca108031636d46c", - "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/faed855a7b5f4d4637717c2b3863e277116beb36", + "reference": "faed855a7b5f4d4637717c2b3863e277116beb36", "shasum": "" }, "require": { @@ -5324,7 +5324,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.13.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.3" }, "funding": [ { @@ -5332,7 +5332,7 @@ "type": "tidelift" } ], - "time": "2025-04-29T12:36:36+00:00" + "time": "2025-07-05T12:25:42+00:00" }, { "name": "nikic/php-parser", diff --git a/docker-compose.yml b/docker-compose.yml index a01165d949..66b9609eb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -214,7 +214,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.1.2 + image: appwrite/console:6.1.12 restart: unless-stopped networks: - appwrite @@ -441,10 +441,12 @@ services: appwrite-worker-builds: entrypoint: worker-builds <<: *x-logging - container_name: appwrite-worker-builds image: appwrite-dev networks: - appwrite + deploy: + mode: replicated + replicas: 2 volumes: - appwrite-functions:/storage/functions:rw - appwrite-sites:/storage/sites:rw diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index e56f935a2f..900261e6d5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -274,10 +274,8 @@ class Builds extends Action $deployment->setAttribute('status', 'processing'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -525,10 +523,8 @@ class Builds extends Action $deployment->setAttribute('status', 'building'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -1063,10 +1059,8 @@ class Builds extends Action $deployment->setAttribute('status', 'ready'); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -1080,6 +1074,7 @@ class Builds extends Action Console::success("Build id: $deploymentId created"); /** Set auto deploy */ + $activateBuild = true; if ($deployment->getAttribute('activate') === true) { // Check if current active deployment started later than this deployment $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); @@ -1090,6 +1085,9 @@ class Builds extends Action $currentActiveStartTime = $currentActiveDeployment->getAttribute('buildStartedAt', ''); $currentActiveEndTime = $currentActiveDeployment->getAttribute('buildEndedAt', ''); $deploymentStartTime = $deployment->getAttribute('buildStartedAt', ''); + $tentativeEndTime = DateTime::now(); + $deployment->setAttribute('buildEndedAt', $tentativeEndTime); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document(['buildEndedAt' => $tentativeEndTime])); $deploymentEndTime = $deployment->getAttribute('buildEndedAt', ''); // Skip auto-activation if: @@ -1098,61 +1096,63 @@ class Builds extends Action if ((!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime > $deploymentStartTime) && (!empty($currentActiveEndTime) && !empty($deploymentEndTime) && $currentActiveEndTime < $deploymentEndTime)) { Console::info('Skipping auto-activation as current deployment is more recent'); - return; + $activateBuild = false; } } } - $resource->setAttribute('live', true); - switch ($resource->getCollection()) { - case 'functions': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); + if ($activateBuild) { + $resource->setAttribute('live', true); + switch ($resource->getCollection()) { + case 'functions': + $resource->setAttribute('deploymentId', $deployment->getId()); + $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); + $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); + $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); - $queries = [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('type', ['deployment']), - Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), - Query::equal('deploymentResourceType', ['function']), - Query::equal('trigger', ['manual']), - Query::equal('deploymentVcsProviderBranch', ['']), - ]; + $queries = [ + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('type', ['deployment']), + Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), + Query::equal('deploymentResourceType', ['function']), + Query::equal('trigger', ['manual']), + Query::equal('deploymentVcsProviderBranch', ['']), + ]; - $rulesUpdated = false; - $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { - $rulesUpdated = true; - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); - }, $queries); - break; - case 'sites': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); - $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); - $queries = [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('type', ['deployment']), - Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), - Query::equal('deploymentResourceType', ['site']), - Query::equal('trigger', ['manual']), - Query::equal('deploymentVcsProviderBranch', ['']), - ]; + $rulesUpdated = false; + $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { + $rulesUpdated = true; + $rule = $rule + ->setAttribute('deploymentId', $deployment->getId()) + ->setAttribute('deploymentInternalId', $deployment->getSequence()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }, $queries); + break; + case 'sites': + $resource->setAttribute('deploymentId', $deployment->getId()); + $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); + $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); + $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); + $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); + $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); + $queries = [ + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('type', ['deployment']), + Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), + Query::equal('deploymentResourceType', ['site']), + Query::equal('trigger', ['manual']), + Query::equal('deploymentVcsProviderBranch', ['']), + ]; - $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); - }, $queries); + $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule + ->setAttribute('deploymentId', $deployment->getId()) + ->setAttribute('deploymentInternalId', $deployment->getSequence()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }, $queries); - break; + break; + } } } @@ -1280,10 +1280,8 @@ class Builds extends Action $deployment->setAttribute('buildLogs', $message); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); - if ($deployment->getInternalId() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus', $deployment->getAttribute('status', '')])); } $queueForRealtime From 1a286ad3f4d3d36e1189608f42f8a9eabe6b14fc Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 00:53:10 +0530 Subject: [PATCH 06/13] Revert replica changes --- docker-compose.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 66b9609eb3..af6610daf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -441,12 +441,10 @@ services: appwrite-worker-builds: entrypoint: worker-builds <<: *x-logging + container_name: appwrite-worker-builds image: appwrite-dev networks: - appwrite - deploy: - mode: replicated - replicas: 2 volumes: - appwrite-functions:/storage/functions:rw - appwrite-sites:/storage/sites:rw From 067b53482f145c65ff91b55a559ab21d6423149e Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 01:02:55 +0530 Subject: [PATCH 07/13] Fix bug --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 900261e6d5..69fa60f97e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1281,7 +1281,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus', $deployment->getAttribute('status', '')])); + $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime From 61a27bfe5505e021ee58fcd60b1967b1db6f4891 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 16:30:43 +0530 Subject: [PATCH 08/13] Simplify auto-activation logic and just update attributes --- .../Modules/Functions/Workers/Builds.php | 73 +++++++++---------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 69fa60f97e..7ab2c84c8a 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -856,9 +856,7 @@ class Builds extends Action $adapter = $resource->getAttribute('adapter', ''); if (empty($adapter)) { - $resource->setAttribute('adapter', $detection->getName()); - $resource->setAttribute('fallbackFile', $detection->getFallbackFile() ?? ''); - $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document(['adapter' => $detection->getName(), 'fallbackFile' => $detection->getFallbackFile() ?? ''])); $deployment->setAttribute('adapter', $detection->getName()); $deployment->setAttribute('fallbackFile', $detection->getFallbackFile() ?? ''); @@ -1083,18 +1081,10 @@ class Builds extends Action $currentActiveDeployment = $dbForProject->getDocument('deployments', $currentActiveDeploymentId); if (!$currentActiveDeployment->isEmpty()) { $currentActiveStartTime = $currentActiveDeployment->getAttribute('buildStartedAt', ''); - $currentActiveEndTime = $currentActiveDeployment->getAttribute('buildEndedAt', ''); $deploymentStartTime = $deployment->getAttribute('buildStartedAt', ''); - $tentativeEndTime = DateTime::now(); - $deployment->setAttribute('buildEndedAt', $tentativeEndTime); - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document(['buildEndedAt' => $tentativeEndTime])); - $deploymentEndTime = $deployment->getAttribute('buildEndedAt', ''); - // Skip auto-activation if: - // 1. Current active deployment started later than deployment that is being activated, AND - // 2. Current active deployment finished earlier than deployment that is being activated - if ((!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime > $deploymentStartTime) && - (!empty($currentActiveEndTime) && !empty($deploymentEndTime) && $currentActiveEndTime < $deploymentEndTime)) { + // Skip auto-activation if current active deployment started later than deployment that is being activated + if (!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime > $deploymentStartTime) { Console::info('Skipping auto-activation as current deployment is more recent'); $activateBuild = false; } @@ -1102,13 +1092,14 @@ class Builds extends Action } if ($activateBuild) { - $resource->setAttribute('live', true); switch ($resource->getCollection()) { case 'functions': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('functions', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); $queries = [ Query::equal('projectInternalId', [$project->getSequence()]), @@ -1122,19 +1113,21 @@ class Builds extends Action $rulesUpdated = false; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { $rulesUpdated = true; - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); break; case 'sites': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); - $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), + 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); $queries = [ Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('type', ['deployment']), @@ -1145,10 +1138,10 @@ class Builds extends Action ]; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); break; @@ -1192,10 +1185,10 @@ class Builds extends Action ])); } catch (Duplicate $err) { $rule = $dbForPlatform->getDocument('rules', $ruleId); - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); } $queries = [ @@ -1208,10 +1201,10 @@ class Builds extends Action ]; $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); } } From 9d7e218e993fc51e5ffcde5cc88c791f37aa917b Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 17:12:35 +0530 Subject: [PATCH 09/13] Save result of updateDocument --- .../Modules/Functions/Workers/Builds.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 7ab2c84c8a..9c8d457cb5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -275,7 +275,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -524,7 +524,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -1058,7 +1058,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -1113,7 +1113,7 @@ class Builds extends Action $rulesUpdated = false; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { $rulesUpdated = true; - $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), ])); @@ -1138,7 +1138,7 @@ class Builds extends Action ]; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), ])); @@ -1184,8 +1184,7 @@ class Builds extends Action 'region' => $project->getAttribute('region') ])); } catch (Duplicate $err) { - $rule = $dbForPlatform->getDocument('rules', $ruleId); - $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), ])); @@ -1201,7 +1200,7 @@ class Builds extends Action ]; $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), ])); @@ -1274,7 +1273,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime From a5a1860ba6755dfa597494ba2b6b14ba34d32ccf Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 17:42:23 +0530 Subject: [PATCH 10/13] Use createdAt instead of buildStartTime --- .../Platform/Modules/Functions/Workers/Builds.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 9c8d457cb5..39bed1c09f 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1072,7 +1072,7 @@ class Builds extends Action Console::success("Build id: $deploymentId created"); /** Set auto deploy */ - $activateBuild = true; + $activateBuild = false; if ($deployment->getAttribute('activate') === true) { // Check if current active deployment started later than this deployment $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); @@ -1080,15 +1080,18 @@ class Builds extends Action if (!empty($currentActiveDeploymentId)) { $currentActiveDeployment = $dbForProject->getDocument('deployments', $currentActiveDeploymentId); if (!$currentActiveDeployment->isEmpty()) { - $currentActiveStartTime = $currentActiveDeployment->getAttribute('buildStartedAt', ''); - $deploymentStartTime = $deployment->getAttribute('buildStartedAt', ''); + $currentActiveStartTime = $currentActiveDeployment->getCreatedAt(); + $deploymentStartTime = $deployment->getCreatedAt(); // Skip auto-activation if current active deployment started later than deployment that is being activated - if (!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime > $deploymentStartTime) { + if (!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime < $deploymentStartTime) { + $activateBuild = true; + } else { Console::info('Skipping auto-activation as current deployment is more recent'); - $activateBuild = false; } } + } else { + $activateBuild = true; } if ($activateBuild) { From bc9caeaae09a7b1021030c8650c6fe7036e4d6f9 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 17:45:45 +0530 Subject: [PATCH 11/13] Use ruleId --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 39bed1c09f..5531eb286b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1187,7 +1187,7 @@ class Builds extends Action 'region' => $project->getAttribute('region') ])); } catch (Duplicate $err) { - $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + $rule = $dbForPlatform->updateDocument('rules', $ruleId, new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), ])); From bd63f0cf3d65adb423a81088e2ed1232242c3426 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 8 Jul 2025 17:46:54 +0530 Subject: [PATCH 12/13] Remove empty check --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 5531eb286b..cb4b7a6a18 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1084,7 +1084,7 @@ class Builds extends Action $deploymentStartTime = $deployment->getCreatedAt(); // Skip auto-activation if current active deployment started later than deployment that is being activated - if (!empty($currentActiveStartTime) && !empty($deploymentStartTime) && $currentActiveStartTime < $deploymentStartTime) { + if ($currentActiveStartTime < $deploymentStartTime) { $activateBuild = true; } else { Console::info('Skipping auto-activation as current deployment is more recent'); From 26496e68c4392a5b35e232742076d208c9203fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 8 Jul 2025 14:51:28 +0200 Subject: [PATCH 13/13] Attempt to simplify code --- .../Modules/Functions/Workers/Builds.php | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index cb4b7a6a18..295acec885 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1093,62 +1093,62 @@ class Builds extends Action } else { $activateBuild = true; } + } - if ($activateBuild) { - switch ($resource->getCollection()) { - case 'functions': - $resource = $dbForProject->updateDocument('functions', $resource->getId(), new Document([ - 'live' => true, + if ($activateBuild) { + switch ($resource->getCollection()) { + case 'functions': + $resource = $dbForProject->updateDocument('functions', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); + + $queries = [ + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('type', ['deployment']), + Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), + Query::equal('deploymentResourceType', ['function']), + Query::equal('trigger', ['manual']), + Query::equal('deploymentVcsProviderBranch', ['']), + ]; + + $rulesUpdated = false; + $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { + $rulesUpdated = true; + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), - 'deploymentCreatedAt' => $deployment->getCreatedAt(), ])); + }, $queries); + break; + case 'sites': + $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), + 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); + $queries = [ + Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('type', ['deployment']), + Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), + Query::equal('deploymentResourceType', ['site']), + Query::equal('trigger', ['manual']), + Query::equal('deploymentVcsProviderBranch', ['']), + ]; - $queries = [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('type', ['deployment']), - Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), - Query::equal('deploymentResourceType', ['function']), - Query::equal('trigger', ['manual']), - Query::equal('deploymentVcsProviderBranch', ['']), - ]; - - $rulesUpdated = false; - $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { - $rulesUpdated = true; - $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ - 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), - ])); - }, $queries); - break; - case 'sites': - $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document([ - 'live' => true, + $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ 'deploymentId' => $deployment->getId(), 'deploymentInternalId' => $deployment->getSequence(), - 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), - 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), - 'deploymentCreatedAt' => $deployment->getCreatedAt(), ])); - $queries = [ - Query::equal('projectInternalId', [$project->getSequence()]), - Query::equal('type', ['deployment']), - Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), - Query::equal('deploymentResourceType', ['site']), - Query::equal('trigger', ['manual']), - Query::equal('deploymentVcsProviderBranch', ['']), - ]; + }, $queries); - $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ - 'deploymentId' => $deployment->getId(), - 'deploymentInternalId' => $deployment->getSequence(), - ])); - }, $queries); - - break; - } + break; } }