fix: server status job

This commit is contained in:
Andras Bacsai 2024-01-17 11:52:56 +01:00
parent b6ce2e9122
commit a635e51486
5 changed files with 11 additions and 4 deletions

View File

@ -72,7 +72,7 @@ class Kernel extends ConsoleKernel
} }
} }
foreach ($servers as $server) { foreach ($servers as $server) {
$schedule->job(new ServerStatusJob($server))->everyFiveMinutes()->onOneServer(); $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer();
} }
} }
private function instance_auto_update($schedule) private function instance_auto_update($schedule)

View File

@ -204,7 +204,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
if (data_get($this->application, 'settings.is_build_server_enabled')) { if (data_get($this->application, 'settings.is_build_server_enabled')) {
$teamId = data_get($this->application, 'environment.project.team.id'); $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) { if ($buildServers->count() === 0) {
$this->application_deployment_queue->addLogEntry("Build server feature activated, but no suitable build server found. Using the deployment server."); $this->application_deployment_queue->addLogEntry("Build server feature activated, but no suitable build server found. Using the deployment server.");
$this->build_server = $this->server; $this->build_server = $this->server;

View File

@ -44,8 +44,8 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
public function handle() public function handle()
{ {
if (!$this->server->isServerReady($this->tries)) { if (!$this->server->isFunctional()) {
return 'Server is not reachable.'; return 'Server is not ready.';
}; };
try { try {
if ($this->server->isSwarm()) { if ($this->server->isSwarm()) {

View File

@ -38,6 +38,9 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
public function handle() public function handle()
{ {
try { try {
if (!$this->server->isServerReady($this->tries)) {
throw new \RuntimeException('Server is not ready.');
};
if ($this->server->isFunctional()) { if ($this->server->isFunctional()) {
$this->cleanup(notify: false); $this->cleanup(notify: false);
} }

View File

@ -141,6 +141,10 @@ class Server extends BaseModel
{ {
return $this->ip === 'host.docker.internal' || $this->id === 0; 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() public function skipServer()
{ {
if ($this->ip === '1.2.3.4') { if ($this->ip === '1.2.3.4') {