From a635e5148668d3299fa94255a440d9cc8d0a5482 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 17 Jan 2024 11:52:56 +0100 Subject: [PATCH] fix: server status job --- app/Console/Kernel.php | 2 +- app/Jobs/ApplicationDeploymentJob.php | 2 +- app/Jobs/ContainerStatusJob.php | 4 ++-- app/Jobs/ServerStatusJob.php | 3 +++ app/Models/Server.php | 4 ++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ac4626af1..50db6d681 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -72,7 +72,7 @@ class Kernel extends ConsoleKernel } } foreach ($servers as $server) { - $schedule->job(new ServerStatusJob($server))->everyFiveMinutes()->onOneServer(); + $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer(); } } private function instance_auto_update($schedule) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 1a243c359..d9a7176a8 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -204,7 +204,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted if (data_get($this->application, 'settings.is_build_server_enabled')) { $teamId = data_get($this->application, 'environment.project.team.id'); - $buildServers = Server::where('team_id', $teamId)->whereRelation('settings', 'is_build_server', true)->get(); + $buildServers = Server::buildServers($teamId)->get(); if ($buildServers->count() === 0) { $this->application_deployment_queue->addLogEntry("Build server feature activated, but no suitable build server found. Using the deployment server."); $this->build_server = $this->server; diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index c28e266dd..b9fa3443f 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -44,8 +44,8 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function handle() { - if (!$this->server->isServerReady($this->tries)) { - return 'Server is not reachable.'; + if (!$this->server->isFunctional()) { + return 'Server is not ready.'; }; try { if ($this->server->isSwarm()) { diff --git a/app/Jobs/ServerStatusJob.php b/app/Jobs/ServerStatusJob.php index 2a3b41a2a..6272d442d 100644 --- a/app/Jobs/ServerStatusJob.php +++ b/app/Jobs/ServerStatusJob.php @@ -38,6 +38,9 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted public function handle() { try { + if (!$this->server->isServerReady($this->tries)) { + throw new \RuntimeException('Server is not ready.'); + }; if ($this->server->isFunctional()) { $this->cleanup(notify: false); } diff --git a/app/Models/Server.php b/app/Models/Server.php index a29293a02..1e41a808c 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -141,6 +141,10 @@ class Server extends BaseModel { return $this->ip === 'host.docker.internal' || $this->id === 0; } + static public function buildServers($teamId) + { + return Server::whereTeamId($teamId)->whereRelation('settings', 'is_reachable', true)->whereRelation('settings', 'is_build_server', true); + } public function skipServer() { if ($this->ip === '1.2.3.4') {