Files
apimacro/vendor/spatie/laravel-backup/docs/monitoring-the-health-of-all-backups/creating-your-custom-health-check.md

23 lines
1.1 KiB
Markdown
Raw Normal View History

2024-05-07 12:17:25 +02:00
---
title: Creating your custom health check
weight: 2
---
You can create your own custom health check by letting a class extend `Spatie\Backup\Tasks\Monitor\HealthCheck`.
That base class contains one abstract method that you should implement.
```php
public function checkHealth(BackupDestination $backupDestination);
```
If your check determines that the backup is not healthy it should throw a `Spatie\Backup\Exceptions\InvalidHealthCheck` exception. The `HealthCheck` base class contains three helpful methods that helps you do this.
- `fail($message)`: will throw the right exception under the hood.
- `failIf(bool $condition, string $message)`: will throw the right exception if `$condition` is `true`
- `failUnless(bool $condition, string $message)`: will throw the right exception if `$condition` is `false`
You should register your custom health check in the `health_checks` key of the `backup.php` config file.
To see an example of a `HealthCheck`, go read the could of the `MaximumAgeInDays` and `MaximumStorageInMegabytes` health checks that are provided by the package.