Skip to content

Commit

Permalink
add default notification interval
Browse files Browse the repository at this point in the history
  • Loading branch information
david-d-h committed Oct 10, 2023
1 parent 141b0be commit c9f180a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/ok.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'notifiable' => Notifiable::class,

'interval' => now()->subMinutes(15),

'via' => [
// 'discord' => [
// 'channel' => 123456790,
Expand Down
10 changes: 5 additions & 5 deletions src/Checks/Base/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Check

protected int $repeatSeconds;

protected Carbon $reportTimeout;
protected Carbon $reportInterval;

protected ?string $name = null;

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Listeners/SendCheckFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
}

0 comments on commit c9f180a

Please sign in to comment.