refactor(application): enhance application stopping logic to support multiple servers

This commit is contained in:
Andras Bacsai
2025-05-26 21:44:34 +02:00
parent be89205d01
commit 102bdb5bc3
5 changed files with 49 additions and 41 deletions

View File

@@ -259,25 +259,15 @@ class Application extends BaseModel
return Application::whereRelation('environment.project.team', 'id', currentTeam()->id)->orderBy('name');
}
public function getContainersToStop(bool $previewDeployments = false): array
public function getContainersToStop(Server $server, bool $previewDeployments = false): array
{
$containers = $previewDeployments
? getCurrentApplicationContainerStatus($this->destination->server, $this->id, includePullrequests: true)
: getCurrentApplicationContainerStatus($this->destination->server, $this->id, 0);
? getCurrentApplicationContainerStatus($server, $this->id, includePullrequests: true)
: getCurrentApplicationContainerStatus($server, $this->id, 0);
return $containers->pluck('Names')->toArray();
}
public function stopContainers(array $containerNames, $server, int $timeout = 30)
{
foreach ($containerNames as $containerName) {
instant_remote_process(command: [
"docker stop --time=$timeout $containerName",
"docker rm -f $containerName",
], server: $server, throwError: false);
}
}
public function deleteConfigurations()
{
$server = data_get($this, 'destination.server');