fix: few fixes and use new ServerReachabilityChanged event

This commit is contained in:
peaklabs-dev
2024-12-16 14:06:53 +01:00
parent 5571aa4530
commit 80425a16ee

View File

@@ -6,6 +6,7 @@ use App\Actions\Proxy\StartProxy;
use App\Actions\Server\InstallDocker; use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel; use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes; use App\Enums\ProxyTypes;
use App\Events\ServerReachabilityChanged;
use App\Jobs\CheckAndStartSentinelJob; use App\Jobs\CheckAndStartSentinelJob;
use App\Notifications\Server\Reachable; use App\Notifications\Server\Reachable;
use App\Notifications\Server\Unreachable; use App\Notifications\Server\Unreachable;
@@ -1050,7 +1051,7 @@ $schema://$host {
ray('Unreachable count: '.$this->unreachable_count); ray('Unreachable count: '.$this->unreachable_count);
if ($this->unreachable_count === 1) { if ($this->unreachable_count === 1) {
$this->settings->is_reachable = true; $this->settings->is_reachable = true;
$this->settings->saveQuietly(); $this->settings->save();
return; return;
} }
@@ -1060,21 +1061,22 @@ $schema://$host {
'unreachable_count' => $this->unreachable_count, 'unreachable_count' => $this->unreachable_count,
]); ]);
$failedChecks = 0; $failedChecks = 0;
for ($i = 0; $i < 2; $i++) { for ($i = 0; $i < 3; $i++) {
sleep(5);
$status = $this->status(); $status = $this->status();
sleep(5);
ray('Check attempt '.($i + 1), ['status' => $status]); ray('Check attempt '.($i + 1), ['status' => $status]);
if (! $status) { if (! $status) {
$failedChecks++; $failedChecks++;
} }
} }
ray('Additional checks complete', [ ray('Additional checks complete', [
'failed_checks' => $failedChecks, 'failed_checks' => $failedChecks,
'will_send_notification' => ($failedChecks === 2 && ! $unreachableNotificationSent), 'will_send_notification' => ($failedChecks === 3 && ! $unreachableNotificationSent),
]); ]);
if ($failedChecks === 2 && ! $unreachableNotificationSent) { if ($failedChecks === 3 && ! $unreachableNotificationSent) {
ray('Sending unreachable notification'); ray('Sending unreachable notification');
$this->sendUnreachableNotification(); $this->sendUnreachableNotification();
} }
@@ -1109,6 +1111,7 @@ $schema://$host {
if ($this->settings->is_reachable === false) { if ($this->settings->is_reachable === false) {
$this->settings->is_reachable = true; $this->settings->is_reachable = true;
$this->settings->save(); $this->settings->save();
ServerReachabilityChanged::dispatch($this);
} }
return ['uptime' => true, 'error' => null]; return ['uptime' => true, 'error' => null];
@@ -1119,6 +1122,7 @@ $schema://$host {
if ($this->settings->is_reachable === true) { if ($this->settings->is_reachable === true) {
$this->settings->is_reachable = false; $this->settings->is_reachable = false;
$this->settings->save(); $this->settings->save();
ServerReachabilityChanged::dispatch($this);
} }
return ['uptime' => false, 'error' => $e->getMessage()]; return ['uptime' => false, 'error' => $e->getMessage()];
@@ -1209,6 +1213,7 @@ $schema://$host {
$this->settings->is_reachable = true; $this->settings->is_reachable = true;
$this->settings->is_usable = true; $this->settings->is_usable = true;
$this->settings->save(); $this->settings->save();
ServerReachabilityChanged::dispatch($this);
return true; return true;
} }