mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix: hand activation back when a queued deployment is canceled
deactivateOthers() clears `activate` on the other pending deployments so the one being dispatched wins when it finishes. A cancel landing between the queued transition and that call left the resource with nothing able to go live: the replacement was canceled, and the deployments it displaced could no longer activate when their own builds finished. Return the ids deactivateOthers() cleared, and hand the claim back to exactly those deployments when the dispatch turns out to have been canceled. No job is submitted in that case either. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
396a03bc8a
commit
f0be2d9bb3
1 file changed
+28
-3
@@ -152,7 +152,20 @@ readonly class Deployments
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
$this->deactivateOthers($resource, $deployment);
|
||||
// Claiming activation takes it away from the other pending deployments,
|
||||
// so a cancel landing while we do it would leave nothing able to go
|
||||
// live. Hand the claim back to exactly the deployments it was taken
|
||||
// from, and stop before submitting a job for a canceled deployment.
|
||||
$deactivated = $this->deactivateOthers($resource, $deployment);
|
||||
if ($deactivated !== [] && $this->status($deployment->getId()) === 'canceled') {
|
||||
foreach ($deactivated as $other) {
|
||||
$this->dbForProject->updateDocument('deployments', $other, new Document([
|
||||
'activate' => true,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->dbForProject->getDocument('deployments', $deployment->getId());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->jobs->create(...static::payload($this->project, $resource, $deployment, $this->platform, $source));
|
||||
@@ -187,11 +200,14 @@ readonly class Deployments
|
||||
/**
|
||||
* Deactivates any other active deployment for $resource before this one
|
||||
* goes live, called once the deployment is queued for building.
|
||||
*
|
||||
* @return array<string> The ids it deactivated, so the caller can hand the
|
||||
* claim back if this deployment never gets to build.
|
||||
*/
|
||||
protected function deactivateOthers(Document $resource, Document $deployment): void
|
||||
protected function deactivateOthers(Document $resource, Document $deployment): array
|
||||
{
|
||||
if (!$deployment->getAttribute('activate', false)) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
$others = $this->dbForProject->find('deployments', [
|
||||
@@ -201,11 +217,20 @@ readonly class Deployments
|
||||
Query::notEqual('$id', $deployment->getId()),
|
||||
]);
|
||||
|
||||
$deactivated = [];
|
||||
foreach ($others as $other) {
|
||||
$this->dbForProject->updateDocument('deployments', $other->getId(), new Document([
|
||||
'activate' => false,
|
||||
]));
|
||||
$deactivated[] = $other->getId();
|
||||
}
|
||||
|
||||
return $deactivated;
|
||||
}
|
||||
|
||||
private function status(string $deploymentId): string
|
||||
{
|
||||
return $this->dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status', '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user