Scheduler Methods
The package adds five methods to Laravel's scheduled events (Illuminate\Console\Scheduling\Event, which also covers callback and job events). They let you tune monitoring per task directly in your schedule definition. This page is the reference for all of them.
Methods on this page:
All of them return the event, so they chain with Laravel's own methods in any order:
Schedule::command('reports:send')
->dailyAt('02:00')
->monitorName('daily-report')
->graceTimeInMinutes(30)
->storeOutputInDb();
How the settings are stored: the values are not stored on the event object itself but in a
MonitoredScheduledTaskssingleton, keyed by the event object's identity. They exist only in memory, for the lifetime of the process that built the schedule, which is why they must be part of the schedule definition (they are applied again in everyschedule:run,schedule-monitor:sync, andschedule-monitor:listprocess).
monitorName
| Property | Value |
|---|---|
| Signature | monitorName(string $monitorName) |
| Default | The derived name |
| Used by | Sync, list, run-time event matching, Oh Dear check name |
Sets the name that identifies the task. Required for closures; recommended for any task whose default name is long, unstable, or contains secrets.
Schedule::call(fn () => 1 + 1)->hourly()->monitorName('addition-closure');
Changing a name later deletes the old history on the next full sync. See Renaming a Task.
graceTimeInMinutes
| Property | Value |
|---|---|
| Signature | graceTimeInMinutes(int $graceTimeInMinutes) |
| Default | schedule-monitor.oh_dear.grace_time_in_minutes (5) |
| Used by | List (late detection), sync (stored in grace_time_in_minutes), Oh Dear check |
The number of minutes a run may take after its scheduled start before it counts as late. Think of it as the time the task normally needs to finish, plus a margin.
// Oh Dear notifies you if this daily task has not finished by 00:10.
Schedule::command('your-command')->daily()->graceTimeInMinutes(10);
The value is used in two places:
- Locally,
schedule-monitor:listmarks the last finish red when the next expected run plus the grace time has passed without a new finish (the exact rule). - At Oh Dear, the grace time is sent with the cron check during the sync. Oh Dear waits that long for the finish ping before notifying you.
Note: The global default lives under the
oh_dearkey of the config file (oh_dear.grace_time_in_minutes) but it also applies to the local list, even when Oh Dear is not used. A changed grace time only reaches Oh Dear after the next sync, and with--keep-oldonly for tasks that are new at Oh Dear.
doNotMonitor
| Property | Value |
|---|---|
| Signature | doNotMonitor(bool $bool = true) |
| Default | Monitored |
| Used by | Sync, list |
Excludes a task from monitoring entirely. The sync skips it and, unless --keep-old is used, deletes an existing row for it (with its log items). It no longer appears in the list.
Schedule::command('telescope:prune')->daily()->doNotMonitor();
The boolean argument makes conditional opt-outs easy:
Schedule::command('horizon:snapshot')
->everyFiveMinutes()
->doNotMonitor(! app()->isProduction());
Note:
doNotMonitor()works through the sync. The run-time event listeners only check whether a row exists for the task's name, so if a row survives (for example because the sync ran with--keep-old), runs keep being logged.
Tasks marked doNotMonitor() that have no name still appear under Unnamed Tasks in the list.
doNotMonitorAtOhDear
| Property | Value |
|---|---|
| Signature | doNotMonitorAtOhDear(bool $bool = true) |
| Default | Monitored at Oh Dear (when Oh Dear is configured) |
| Used by | Sync |
Keeps the task in the local database monitoring but leaves it out of Oh Dear. On every sync the task's ping_url is set to null, so no pings are dispatched for it, and it is not included in the cron checks sent to Oh Dear. With a full sync, an existing Oh Dear check for it is removed.
Schedule::command('cache:prune-stale-tags')->hourly()->doNotMonitorAtOhDear();
Use it for noisy or unimportant tasks that you still want a history for.
Note: The README's prose mentions
doMonitorAtOhDear, but the method isdoNotMonitorAtOhDear(); there is nodoMonitorAtOhDearmethod.
storeOutputInDb
| Property | Value |
|---|---|
| Signature | storeOutputInDb(bool $bool = true) |
| Default | Output is not stored |
| Used by | Run-time event listeners |
Stores the task's output in the output key of the meta column of its finished (or exit-code failed) log item.
Schedule::command('reports:send')->daily()->storeOutputInDb();
$logItem = MonitoredScheduledTask::findByName('reports:send')
->logItems()
->where('type', 'finished')
->first();
echo $logItem->meta['output'];
How it works: calling the method also calls Laravel's ensureOutputIsBeingCaptured() on the event, which redirects the output to a temporary file when no output file was configured. When the task finishes, the package reads the whole content of the event's output file and stores it. Empty output is stored as null.
Things to know:
- Commands and shell commands produce output. Closures and jobs run inside the scheduler process and do not write to the output file, so for them the stored output is normally
null. - With
appendOutputTo($file), the file keeps growing, and every log item stores the entire file, including the output of all previous runs. PrefersendOutputTo()(which overwrites) or no output file at all. - There is no size limit. A task that prints a lot of output stores all of it in a JSON column on every run. Combine with pruning.
exception-basedfaileditems never contain output (onlyfailure_message).