diff --git a/config/ok.php b/config/ok.php index 94d9fea..48d8aa0 100644 --- a/config/ok.php +++ b/config/ok.php @@ -11,6 +11,8 @@ 'notifiable' => Notifiable::class, + 'interval' => now()->subMinutes(15), + 'via' => [ // 'discord' => [ // 'channel' => 123456790, diff --git a/src/Checks/Base/Check.php b/src/Checks/Base/Check.php index 0055264..2590700 100644 --- a/src/Checks/Base/Check.php +++ b/src/Checks/Base/Check.php @@ -27,7 +27,7 @@ abstract class Check protected int $repeatSeconds; - protected Carbon $reportTimeout; + protected Carbon $reportInterval; protected ?string $name = null; @@ -120,14 +120,14 @@ public function markAsCrashed(): Result return new Result(Status::CRASHED); } - public function getReportTimeout(): Carbon + public function getReportInterval(): Carbon { - return $this->reportTimeout; + return $this->reportInterval ?? config('ok.notifications.interval', Carbon::now()->subMinutes(30)); } - public function reportTimeout(Carbon $minimumDelay): static + public function reportInterval(Carbon $minimumDelay): static { - $this->reportTimeout = $minimumDelay; + $this->reportInterval = $minimumDelay; return $this; } diff --git a/src/Listeners/SendCheckFailedNotification.php b/src/Listeners/SendCheckFailedNotification.php index 3ddab8a..e48b066 100644 --- a/src/Listeners/SendCheckFailedNotification.php +++ b/src/Listeners/SendCheckFailedNotification.php @@ -21,7 +21,7 @@ public function handle(CheckFailed $event) $failedNotificationClass = config('ok.notifications.failed_notification'); - $notification = (new $failedNotificationClass($event->check, $event->result)); + $notification = new $failedNotificationClass($event->check, $event->result); $notifiable->notify($notification); @@ -37,8 +37,8 @@ protected function shouldSendNotification(Check $check): bool { $lastRun = OK::lastRun($check::class); - $timeout = $check->getReportTimeout(); + $interval = $check->getReportInterval(); - return $lastRun < $timeout; + return $lastRun < $interval; } }