Health for Laravel
Schedule Check
Schedule Check
Checks for a heartbeat timestamp in cache to verify the scheduler is active.
Configuration
'checks_config' => [
'schedule' => ['max_age_minutes' => 5],
],
Setup
Schedule the built-in heartbeat command in your routes/console.php:
use Illuminate\Support\Facades\Schedule;
Schedule::command('health:heartbeat')->everyMinute();
The command writes the current time to the default cache store under health:schedule:heartbeat for 10 minutes. The check reads the same key from the default store, so every server running the check must share that store with the server running the scheduler.
Or if you prefer a manual approach:
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schedule;
Schedule::call(function () {
Cache::put('health:schedule:heartbeat', now(), 600);
})->everyMinute();
Usage
use Cbox\LaravelHealth\Checks\ScheduleCheck;
'checks' => [
'readiness' => [
ScheduleCheck::class,
],
],
Behavior
- Reads the heartbeat timestamp from the default cache store
- Returns
warningif no heartbeat is found - Returns
criticalif the cached value is not a timestamp (aDateTimeInterface, such asnow()) - Returns
criticalif the heartbeat is more thanmax_age_minutesold, withage_minutesandmax_age_minutesin metadata - Returns
okwhen the heartbeat is fresh, withage_minutesin metadata