Fix server readiness check in ContainerStatusJob and ServerStatusJob
This commit is contained in:
@@ -39,7 +39,9 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
{
|
{
|
||||||
ray("checking container statuses for {$this->server->id}");
|
ray("checking container statuses for {$this->server->id}");
|
||||||
try {
|
try {
|
||||||
$this->server->checkServerRediness();
|
if (!$this->server->isServerReady()) {
|
||||||
|
throw new \Exception('Server is not ready.');
|
||||||
|
};
|
||||||
$containers = instant_remote_process(["docker container ls -q"], $this->server);
|
$containers = instant_remote_process(["docker container ls -q"], $this->server);
|
||||||
if (!$containers) {
|
if (!$containers) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,8 +34,9 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
{
|
{
|
||||||
ray("checking server status for {$this->server->id}");
|
ray("checking server status for {$this->server->id}");
|
||||||
try {
|
try {
|
||||||
$this->server->checkServerRediness();
|
if ($this->server->isServerReady()) {
|
||||||
$this->cleanup(notify: false);
|
$this->cleanup(notify: false);
|
||||||
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage());
|
send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage());
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
|
|||||||
@@ -128,13 +128,15 @@ class Server extends BaseModel
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public function checkServerRediness()
|
public function isServerReady()
|
||||||
{
|
{
|
||||||
$serverUptimeCheckNumber = $this->unreachable_count;
|
$serverUptimeCheckNumber = $this->unreachable_count;
|
||||||
$serverUptimeCheckNumberMax = 3;
|
$serverUptimeCheckNumberMax = 3;
|
||||||
|
|
||||||
$currentTime = now()->timestamp;
|
$currentTime = now()->timestamp;
|
||||||
$runtime5Minutes = 1 * 60;
|
$runtime5Minutes = 1 * 60;
|
||||||
|
|
||||||
|
$isReady = false;
|
||||||
// Run for 1 minutes max and check every 5 seconds for 3 times
|
// Run for 1 minutes max and check every 5 seconds for 3 times
|
||||||
while ($currentTime + $runtime5Minutes > now()->timestamp) {
|
while ($currentTime + $runtime5Minutes > now()->timestamp) {
|
||||||
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
|
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
|
||||||
@@ -165,7 +167,8 @@ class Server extends BaseModel
|
|||||||
$db->update(['status' => 'exited']);
|
$db->update(['status' => 'exited']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new \Exception('Server is not reachable.');
|
$isReady = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$result = $this->validateConnection();
|
$result = $this->validateConnection();
|
||||||
ray('validateConnection: ' . $result);
|
ray('validateConnection: ' . $result);
|
||||||
@@ -177,9 +180,10 @@ class Server extends BaseModel
|
|||||||
Sleep::for(5)->seconds();
|
Sleep::for(5)->seconds();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$isReady = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return $isReady;
|
||||||
}
|
}
|
||||||
public function getDiskUsage()
|
public function getDiskUsage()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user