Oh Dear Setup
The package records your schedule's history locally, but it never sends notifications itself. For alerts, it integrates with Oh Dear's cron job monitoring: every task becomes a cron check at Oh Dear, every finish or failure is pinged to it, and Oh Dear notifies you (by mail, Slack, SMS, webhooks, and other channels configured in Oh Dear) when a ping is missing, late, or reports a failure. This page walks through the setup.
How the Integration Works
- You give the package an Oh Dear API token and the id of an Oh Dear monitor (formerly called a "site").
schedule-monitor:synccreates one cron check per task on that monitor, with the task's name, cron expression, timezone, and grace time. Oh Dear returns a unique ping URL per check, stored in the task'sping_urlcolumn.- When a task finishes or fails, the package dispatches a queued
PingOhDearJobthat POSTs to{ping_url}/finishedor{ping_url}/failed. - Oh Dear knows from the cron expression when each run is due. If no finish ping arrives within the grace time, or a failure ping arrives, it notifies you.
The key advantage over notifications sent from your app: if cron stops calling schedule:run, or the whole server is down, no ping arrives, and Oh Dear notices.
Step 1: Get an API Token and a Monitor Id
- Create an API token in Oh Dear's user settings: https://ohdear.app/user/api-tokens.
- Find the monitor id on the settings page of the monitor that should own the cron checks, typically the monitor of the application's website.
Step 2: Configure the Package
Set the environment variables:
OH_DEAR_API_TOKEN=your-api-token
OH_DEAR_MONITOR_ID=12345
OH_DEAR_QUEUE=oh-dear-pings
These map to schedule-monitor.oh_dear.api_token, monitor_id, and queue. You do not need to publish the config file for this; publish it only if you want to change other Oh Dear settings (see Configuration).
The queue is optional but recommended (see Step 5).
Step 3: Verify the Connection
php artisan schedule-monitor:verify
The last line should read All ok! Run php artisan schedule-monitor:sync to sync your scheduled tasks with oh dear. If not, the error tells you what is missing. See schedule-monitor:verify.
Step 4: Sync the Schedule
php artisan schedule-monitor:sync
The output now includes Start syncing schedule with Oh Dear... and Successfully synced schedule with Oh Dear!, and the monitor in Oh Dear lists one cron check per task.
Warning: A normal sync makes the monitor's cron checks match your schedule exactly and removes any other cron checks on that monitor. If you also monitor cron jobs outside this Laravel app on the same monitor, use
php artisan schedule-monitor:sync --keep-old, and read its limitations.
Step 5: Run a Queue Worker for the Pings
Pings are sent by a queued job so that a slow or unreachable Oh Dear never delays your scheduled tasks. That makes the queue part of your monitoring: if the worker is down or the queue is backed up, pings arrive late and Oh Dear sends false "late" notifications.
The README recommends a dedicated queue for these jobs:
OH_DEAR_QUEUE=oh-dear-pings
php artisan queue:work --queue=oh-dear-pings
or add oh-dear-pings to the queues of an existing worker or Horizon supervisor. A ping job that has waited longer than retry_job_for_minutes (default 10) is no longer retried, see Oh Dear Pings.
If the application uses the sync queue driver, the ping is sent inside the scheduler process instead. That works, but the HTTP retries (see Oh Dear Pings) then block the scheduler while Oh Dear is unreachable.
Step 6: Tune Grace Times
Oh Dear waits for the finish ping for the task's grace time after each scheduled start (default 5 minutes). Tasks that take longer need more:
// Oh Dear notifies you if this task has not finished by 00:10.
Schedule::command('your-command')->daily()->graceTimeInMinutes(10);
Run the sync again after changing grace times; Oh Dear only learns about them during a sync.
Excluding Tasks from Oh Dear
Keep a task in the local history but out of Oh Dear with doNotMonitorAtOhDear():
Schedule::command('your-command')->daily()->doNotMonitorAtOhDear();
See Scheduler Methods.
Optional: Starting Pings
By default only the finish and failure of a run are sent. Oh Dear does not need the start for notifications, but if you want Oh Dear to see when a run began (and measure its duration on its side), enable starting pings:
OH_DEAR_SEND_STARTING_PING=true
Use the literal value true. See Oh Dear Pings for why other truthy values like 1 misbehave.
Multitenancy
If the application uses spatie/laravel-multitenancy with tenant-aware queued jobs, the ping job fails because no tenant is set when it runs. Add it to the not_tenant_aware_jobs array in config/multitenancy.php:
'not_tenant_aware_jobs' => [
// ...
\Spatie\ScheduleMonitor\Jobs\PingOhDearJob::class,
],
If you configured a custom ping job, list your class instead.
One Monitor per Environment
The sync uses only the tasks of the current environment, and a full sync replaces the monitor's cron checks. Never point staging and production at the same OH_DEAR_MONITOR_ID; give each environment its own monitor or leave the monitor id empty where you do not want notifications. See Environments and Shared Oh Dear Monitors.