fix: server unreachable count

This commit is contained in:
Andras Bacsai
2023-10-09 12:07:42 +02:00
parent 8004a40139
commit 933ec5741d
2 changed files with 56 additions and 19 deletions

View File

@@ -46,28 +46,37 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
try { try {
ray("checking server status for {$this->server->name}"); ray("checking server status for {$this->server->name}");
// ray()->clearAll(); // ray()->clearAll();
$serverUptimeCheckNumber = 0; $serverUptimeCheckNumber = $this->server->unreachable_count;
$serverUptimeCheckNumberMax = 3; $serverUptimeCheckNumberMax = 3;
while (true) {
ray('checking # ' . $serverUptimeCheckNumber); ray('checking # ' . $serverUptimeCheckNumber);
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) { if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
if ($this->server->unreachable_email_sent === false) { if ($this->server->unreachable_email_sent === false) {
ray('Server unreachable, sending notification...'); ray('Server unreachable, sending notification...');
// $this->server->team->notify(new Unreachable($this->server)); // $this->server->team->notify(new Unreachable($this->server));
$this->server->update(['unreachable_email_sent' => true]);
} }
$this->server->settings()->update([ $this->server->settings()->update([
'is_reachable' => false, 'is_reachable' => false,
'unreachable_count' => 0,
]); ]);
$this->server->update(['unreachable_email_sent' => true]);
return; return;
} }
$result = $this->server->validateConnection(); $result = $this->server->validateConnection();
if ($result) { if ($result) {
break; $this->server->settings()->update([
} 'is_reachable' => true,
'unreachable_count' => 0,
]);
} else {
$serverUptimeCheckNumber++; $serverUptimeCheckNumber++;
sleep(5); $this->server->settings()->update([
'is_reachable' => false,
'unreachable_count' => $serverUptimeCheckNumber,
]);
return;
} }
if (data_get($this->server, 'unreachable_email_sent') === true) { if (data_get($this->server, 'unreachable_email_sent') === true) {
ray('Server is reachable again, sending notification...'); ray('Server is reachable again, sending notification...');
// $this->server->team->notify(new Revived($this->server)); // $this->server->team->notify(new Revived($this->server));
@@ -82,7 +91,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
'is_usable' => true 'is_usable' => true
]); ]);
} }
$this->server->validateDockerEngine(true); // $this->server->validateDockerEngine(true);
$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;

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->integer('unreachable_count')->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('unreachable_count');
});
}
};