Naming Tasks
Every monitored task is identified by its name. The name is the key of its row in monitored_scheduled_tasks, the key used to match scheduler events to that row, and the name of its cron check at Oh Dear. This page explains how names are derived automatically, when you must set one yourself, and what happens when names collide or change.
How Default Names Are Derived
When a task has no monitorName(), the package classifies the scheduled event and derives a name from it. The checks run in this order, and the first match wins:
| Type | Matches | Default name | Example definition | Resulting name |
|---|---|---|---|---|
closure |
A callback event whose display summary is Closure or Callback (no description set) |
none | Schedule::call(fn () => ...) |
(unnamed) |
job |
A callback event with a description that is an existing class name | The class name | Schedule::job(new SyncInventory) |
App\Jobs\SyncInventory |
command |
A command event whose command line contains 'artisan' ("artisan" on Windows) |
Everything after 'artisan' |
Schedule::command('reports:send --daily') |
reports:send --daily |
shell |
Anything else | The full command line | Schedule::exec('rsync -a /data /backup') |
rsync -a /data /backup |
The type is stored in the type column and shown in parentheses in the list output, for example inspire (command).
Consequences of these rules worth knowing:
- Command names include the arguments.
command('model:prune', ['--model' => ...])is named after the full compiled argument list, quoting included. Changing an argument changes the name. - Commands given as a class (
Schedule::command(SendReports::class)) are resolved by Laravel to the command's signature name, so the monitor name is the command name, such asreports:send. - Names longer than 255 characters are truncated to 255 characters, to fit the
namecolumn. This also applies to names set withmonitorName(). Two long names that share the same first 255 characters become duplicates. - Shell task names can contain secrets. If you pass a token on the command line of
exec(), it ends up in the database and, with Oh Dear, in the cron check name. UsemonitorName()to avoid that.
Tasks Without a Name
Closures and invokable objects scheduled with Schedule::call() have no natural name. They are reported under Unnamed Tasks in schedule-monitor:list, skipped by the sync, and their events are ignored.
A less obvious case: calling Laravel's ->name() or ->description() on a callback does not give it a monitor name, and can even remove one. These methods set the event's description, which changes the classification above:
| Definition | Classified as | Monitor name |
|---|---|---|
Schedule::call($fn)->name('cleanup') |
shell (the description is not a class) |
(unnamed), because a callback has no command line |
Schedule::job(new SyncInventory)->name('sync') |
shell |
(unnamed) |
Schedule::job(new SyncInventory) |
job |
App\Jobs\SyncInventory |
The same applies when a job class defines a displayName() method that does not return a class name, because Laravel uses it as the job's description. In all these cases, use monitorName().
Setting a Name with monitorName()
// routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('reports:send --daily')->dailyAt('02:00')->monitorName('daily-report');
Schedule::call(fn () => cache()->forget('stats'))
->hourly()
->name('clear-stats-cache') // needed by Laravel for withoutOverlapping()
->withoutOverlapping()
->monitorName('clear-stats-cache'); // needed by the schedule monitor
monitorName() always wins over the default name. Names should be unique and stable: they are the identity of the task's history.
Good reasons to set a name even when a default exists:
- the command line is long, contains changing arguments, or contains secrets,
- you want readable names in Oh Dear's dashboard and notifications,
- you plan to change arguments later and want to keep the history.
Duplicate Names
The sync keeps the first task with a given name (in schedule order) and ignores the others. schedule-monitor:list shows the ignored ones under Duplicate Tasks:
Duplicate Tasks
These tasks could not be monitored because they have a duplicate name.
dummy (closure) .......................................... Every hour
To monitor these tasks you should add ->monitorName() in the schedule to manually specify a unique name.
For example, both tasks below are named reports:send; only the first one's cron expression is synced:
Schedule::command('reports:send')->dailyAt('02:00');
Schedule::command('reports:send')->dailyAt('14:00');
Warning: At run time, events are matched by name only. When the 14:00 duplicate runs, its start and finish are recorded on the row of the 02:00 task, and pinged to that task's Oh Dear check. The list and Oh Dear then see runs at times the synced cron expression does not expect. Give each task a unique
monitorName()instead, such asreports:send-nightandreports:send-afternoon.
Renaming a Task
Because the name is the identity of a task, renaming one (by changing monitorName(), or by changing a command's arguments when you rely on the default name) is a delete-and-create:
- After the deployment, events for the new name are ignored until the sync runs, because there is no row with that name yet.
schedule-monitor:synccreates a row for the new name.- Unless you pass
--keep-old, the sync deletes the row for the old name. The foreign key cascades, so all log items of the old name are deleted too. - With Oh Dear, a full sync replaces the old cron check with a new one (and a new ping URL).
If the history matters, export it before renaming, or run the sync with --keep-old and clean up later.