Troubleshooting

This page collects common problems with laravel-schedule-monitor, each with its cause and fix, including several behaviors found in the source code that are easy to trip over.

On this page:

Tasks run but nothing is logged

Cause: the listeners only record events for tasks that have a row in monitored_scheduled_tasks, matched by name. Common reasons for a missing row:

  • the sync was not run after the task was added (the list shows it under Run sync to start monitoring),
  • the task's name changed since the last sync, for example because its command arguments changed,
  • the task has no name,
  • the task only runs in another environment than the one where the sync ran.

Fix: run php artisan schedule-monitor:sync in the environment where the scheduler runs, and add it to your deploy script. Check schedule-monitor:list.

A task appears under "Unnamed Tasks"

Cause: no name could be derived. This happens for closures and invokable objects, and also for callbacks and jobs on which you called Laravel's ->name() or ->description(), because that changes how the task is classified (details).

Fix: add ->monitorName('a-unique-name').

A task appears under "Duplicate Tasks"

Cause: an earlier task in the schedule has the same name. Only the first one is synced, but at run time both tasks write to the same row and ping the same Oh Dear check.

Fix: give each task a unique monitorName().

A task's history disappeared

Cause: a full sync deletes the rows of tasks that are no longer in the schedule of the current environment, and their log items are deleted by the cascading foreign key. Renaming a task, changing a command's arguments, adding doNotMonitor(), or restricting a task with environments() all count as removing it. Pruning removes log items older than delete_log_items_older_than_days.

Fix: use stable monitorName() values. If you must rename, export the history first, or run the sync with --keep-old. Never run the sync in an environment that shares the database with another one.

The list shows a task as late although it ran

Cause: the task finished later than its next scheduled start plus the grace time, it has been failing (failures do not count as finishes), or its last finish was not recorded. Long-running tasks with the default 5-minute grace time look late until they finish. See When Is a Task Late?.

Fix: set graceTimeInMinutes() to the task's normal duration plus a margin, then sync.

Oh Dear reports late runs that actually ran

Cause: the finish ping reached Oh Dear too late or not at all. Typical reasons:

  • no queue worker is processing the ping queue, or it is busy with other jobs,
  • the ping job expired (retry_job_for_minutes) while Oh Dear or the network was unreachable,
  • the grace time is shorter than the task's duration,
  • the task ran under a different name than the one synced (duplicates, renamed tasks).

Fix: use a dedicated OH_DEAR_QUEUE with its own worker, raise grace times where needed, and enable debug logging or listen to OhDearPingFailed to see failed pings. Check the last_pinged_at column to see when each task last reached Oh Dear.

Tasks with conditions trigger false alerts

Cause: Oh Dear only receives the cron expression. Conditions added with between(), unlessBetween(), when(), or skip() are evaluated by Laravel at run time. When they prevent a run, the package records a skipped log item but sends no ping, so Oh Dear sees a missing run. The README lists these methods as unsupported for this reason. The same applies to other filters that cause skips, such as withoutOverlapping() while the previous run is still active.

Fix: for such tasks, use doNotMonitorAtOhDear() and rely on the local history, or replace the condition with a cron expression that matches the real run times (for example ->cron('0 9-17 * * 1-5') instead of ->hourly()->between('9:00', '17:00')->weekdays()).

Other cron checks vanished from Oh Dear

Cause: a normal sync makes the Oh Dear monitor's cron checks match the schedule, removing all others. A sync from another environment pointing at the same monitor also replaces them.

Fix: use schedule-monitor:sync --keep-old if the monitor holds checks for other cron jobs, and use one Oh Dear monitor per environment.

Pings continue after removing the monitor id

Cause: the ping URLs are stored on each task row, and pinging does not need the API token or monitor id. Without a monitor id the sync skips Oh Dear but does not clear existing ping URLs.

Fix: clear the ping_url column, or mark tasks with doNotMonitorAtOhDear() and sync. See Stopping Oh Dear Monitoring.

Changes to a task are not visible at Oh Dear

Cause: Oh Dear learns about cron expressions and grace times only during a sync, and a --keep-old sync only registers tasks that have never been registered. It neither updates existing checks nor re-registers a task whose registered_on_oh_dear_at is already set.

Fix: run a full sync, without --keep-old. If you cannot (because of foreign checks on the monitor), update the check in Oh Dear by hand, or reset registered_on_oh_dear_at to null for the task and delete its old check in Oh Dear before syncing with --keep-old.

Starting pings are not sent

Cause: dispatching a starting ping requires send_starting_ping to be exactly the boolean true. A value such as OH_DEAR_SEND_STARTING_PING=1 becomes the string "1", which fails that check but still makes the finish ping omit runtime.

Fix: use OH_DEAR_SEND_STARTING_PING=true, then clear and rebuild the config cache.

The "Registered at Oh Dear" column is missing

Cause: a bug in the current source: schedule-monitor:list checks class_exists(OhDear::class) without importing the class, so the check always fails and the Oh Dear column and hint are never rendered, even when Oh Dear works.

Fix: none needed for monitoring itself. Look at the ping_url and registered_on_oh_dear_at columns, or at the monitor in Oh Dear, to see which tasks are registered. See The Oh Dear Column.

Two failed log items for one run

Cause: a command that exits with a non-zero code is recorded as failed from the ScheduledTaskFinished event, and current Laravel versions then also fire ScheduledTaskFailed for the same run, which is recorded again (with a failure_message). Oh Dear receives two failure pings.

Fix: nothing to fix; treat them as one failure when analyzing the history. See How Failures Are Detected.

Runtime and memory are 0

Cause: the task runs with runInBackground(). The package records its finish when schedule:finish runs and does not measure runtime or memory for background tasks. Separately, memory always measures the scheduler process, not the child process of a command.

Fix: compute durations from the created_at of the starting and finished log items.

Output is not stored

Cause: storeOutputInDb() is missing, the task is a closure or job (which do not write to the output file), or the output was empty (stored as null).

Fix: add ->storeOutputInDb() to commands or shell tasks. Avoid combining it with appendOutputTo(), which makes every log item contain the whole accumulated file.

The ping job fails with multitenancy

Cause: with spatie/laravel-multitenancy, queued jobs are tenant aware by default and fail when no tenant is set.

Fix: add \Spatie\ScheduleMonitor\Jobs\PingOhDearJob::class (or your custom job) to not_tenant_aware_jobs in config/multitenancy.php.

Ping jobs show up in Horizon

Cause: silence_ping_oh_dear_job_in_horizon is false, or you use a custom ping job class; only the base PingOhDearJob is silenced automatically.

Fix: add your job class to silenced in config/horizon.php.

InvalidClassException on boot

Cause: a class configured under models does not extend Spatie\ScheduleMonitor\Models\MonitoredScheduledTask or MonitoredScheduledTaskLogItem. The message reads The provided class name {class} does not extend the required package class {package class}. The check runs on every boot, so every request and Artisan command fails.

Fix: make your model extend the package model, or restore the default class in config/schedule-monitor.php. If the config is cached, delete bootstrap/cache/config.php by hand, since Artisan cannot boot.

See Also