Skip to content

Monitor the scheduler

When the scheduler stops, nothing fails: tasks just stop running. The package records each tick of schedule:run and the last run of each task. The scheduler health indicator reports DOWN when the ticks stop, and the scheduledtasks endpoint shows when each task last ran and whether it failed.

The scheduler writes the records, and the web instances read them. Both must use the same cache store. Set it in .env:

.env
ACTUATOR_SCHEDULER_STORE=redis

Without it, the package uses the application’s default cache store.

Recording is on by default. A store that fails never stops a task. When a write throws, for example on a connection timeout, the process logs a warning and writes no more records for the rest of its life. A new process tries again: cron and schedule:work start a new schedule:run process every minute, so a store that hangs until its timeout delays the tasks once per minute at most. A write that the store rejects without an error logs a warning once, and recording goes on.

The indicator is off by default. Add it to health.indicators:

config/actuator.php
'indicators' => [
// ...
'scheduler' => Nwidart\Actuator\Health\Indicators\SchedulerHealthIndicator::class,
],

It is WARNING after 2 minutes without a tick, and DOWN after 5. schedule:work, or a cron entry for schedule:run, ticks every minute. Change the thresholds with arguments:

config/actuator.php
'scheduler' => [SchedulerHealthIndicator::class, ['downAfter' => 10, 'warningAfter' => null]],

Do not add scheduler to the liveness or readiness group of the web pods. A stopped scheduler would then take every web pod out of rotation.

A pod that runs schedule:work has no HTTP server. Use an exec probe with php artisan actuator:health scheduler. It exits 1 when the scheduler is DOWN, so Kubernetes restarts the pod:

scheduler-deployment.yaml
spec:
containers:
- name: scheduler
image: my-app:1.4.2
args: ["php", "artisan", "schedule:work"]
livenessProbe:
exec:
command: ["php", "artisan", "actuator:health", "scheduler"]
initialDelaySeconds: 90
periodSeconds: 60
timeoutSeconds: 10
failureThreshold: 3

initialDelaySeconds gives a new pod time for its first tick. The last tick of a pod that stopped long ago would otherwise make it DOWN.

Put the indicator in a group of its own, and point your monitoring at it:

config/actuator.php
'groups' => [
'liveness' => ['include' => ['ping']],
'readiness' => ['include' => ['readinessState', 'migrations']],
'scheduling' => ['include' => ['scheduler']],
],

/actuator/health/scheduling answers HTTP 503 when the scheduler is DOWN, and HTTP 200 when it is UP or WARNING. See define health groups.

The tick is shared. When several hosts run schedule:run, the indicator reports that one of them ticks, not which one.

Expose the scheduledtasks endpoint and read lastExecution:

Terminal window
curl http://localhost/actuator/scheduledtasks
{
"runnable": { "target": "php artisan reports:send" },
"expression": "0 * * * *",
"timezone": "UTC",
"nextExecution": { "time": "2026-01-01T11:00:00+00:00" },
"lastExecution": {
"time": "2026-01-01T10:00:04+00:00",
"status": "ERROR",
"exception": { "type": "Exception" }
}
}

The exception message is hidden by default, because it can hold a command’s arguments. Set scheduledtasks.show_exceptions to when_authorized or always to show it.

.env
ACTUATOR_SCHEDULER_RECORD=false

The endpoint then leaves out lastExecution, and the indicator reports UNKNOWN.