Refactor server setting model to use waitBeforeDoingSshCheck method

This commit is contained in:
Andras Bacsai
2024-10-22 14:49:23 +02:00
parent 2e9ce3ed2a
commit cec77abaa8
2 changed files with 17 additions and 7 deletions

View File

@@ -116,12 +116,7 @@ class Kernel extends ConsoleKernel
} }
foreach ($servers as $server) { foreach ($servers as $server) {
$last_sentinel_update = $server->sentinel_updated_at; $last_sentinel_update = $server->sentinel_updated_at;
$push_interval_seconds = $server->settings->sentinel_push_interval_seconds; if (Carbon::parse($last_sentinel_update)->isBefore(now()->subSeconds($server->waitBeforeDoingSshCheck()))) {
$wait_before_doing_ssh_check = $push_interval_seconds * 3;
if ($wait_before_doing_ssh_check < 120) {
$wait_before_doing_ssh_check = 120;
}
if (Carbon::parse($last_sentinel_update)->isBefore(now()->subSeconds($wait_before_doing_ssh_check))) {
$schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer(); $schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();
} }
$serverTimezone = $server->settings->server_timezone; $serverTimezone = $server->settings->server_timezone;

View File

@@ -535,9 +535,24 @@ $schema://$host {
$this->save(); $this->save();
} }
/**
* Get the wait time before performing an SSH check.
*
* @return int The wait time in seconds.
*/
public function waitBeforeDoingSshCheck(): int
{
$wait = $this->settings->sentinel_push_interval_seconds * 3;
if ($wait < 120) {
$wait = 120;
}
return $wait;
}
public function isSentinelLive() public function isSentinelLive()
{ {
return Carbon::parse($this->sentinel_updated_at)->isAfter(now()->subMinutes(4)); return Carbon::parse($this->sentinel_updated_at)->isAfter(now()->subSeconds($this->waitBeforeDoingSshCheck()));
} }
public function isSentinelEnabled() public function isSentinelEnabled()