Oh Dear Pings
After a sync, every task registered at Oh Dear has a ping URL. This page explains how pings are sent: which events trigger them, what each request contains, how retries and expiry work, and how to customize the ping job, react to failed pings, and debug connectivity problems.
On this page:
- When a Ping Is Sent
- Ping Requests
- Starting Pings
- Retries and Expiry
- Choosing the Queue
- Horizon
- Custom Ping Endpoints
- Debug Logging
- The OhDearPingFailed Event
- Using a Custom Ping Job
When a Ping Is Sent
A ping is dispatched as a queued Spatie\ScheduleMonitor\Jobs\PingOhDearJob when all of these hold:
- a log item was just created for the task,
- the task's row has a non-empty
ping_url(set by the sync when Oh Dear is configured and the task is not markeddoNotMonitorAtOhDear()), - the log item type is
finishedorfailed, orstartingwhensend_starting_pingis enabled.
skipped log items never cause a ping.
Ping Requests
Every ping is an HTTP POST to the task's ping URL plus a suffix, sent with Laravel's HTTP client (which encodes the body as JSON by default). The body is taken from the log item's meta:
| Log item type | URL | Body |
|---|---|---|
starting |
{ping_url}/starting |
empty |
finished |
{ping_url}/finished |
runtime, exit_code, memory (runtime is left out when starting pings are enabled) |
failed |
{ping_url}/failed |
failure_message (only present for exception-based failures) |
For example, a finished run produces a request like:
POST https://ping.ohdear.app/<uuid>/finished
{"runtime": 3.42, "exit_code": 0, "memory": 46137344}
The output stored by storeOutputInDb() is not sent to Oh Dear.
After a successful ping, the task's last_pinged_at column is set to the current time, so you can see in the database when Oh Dear last heard from each task.
Starting Pings
| Config key | oh_dear.send_starting_ping |
|---|---|
| Environment variable | OH_DEAR_SEND_STARTING_PING |
| Default | false |
When enabled, a ping is also sent when a run starts. Oh Dear then knows the start time and can compute the runtime itself, which is why the package omits runtime from the finish ping in that mode.
Warning: The two places that read this setting compare it differently. Dispatching the starting ping requires the value to be exactly the boolean
true, while leavingruntimeout of the finish ping only requires a truthy value. Laravel'senv()converts the stringtrueto a boolean, but leaves1as the string"1". WithOH_DEAR_SEND_STARTING_PING=1, no starting pings are sent and the finish pings lose their runtime. Always usetrueorfalse.
Retries and Expiry
Each ping goes through two layers of retrying:
- Inside one job attempt, the HTTP request is tried up to 3 times, waiting
retry_delay_msmilliseconds between tries (default10000, environment variableOH_DEAR_RETRY_DELAY_MS). Connection errors and HTTP error responses both count as failures. - If all tries fail, the job fires an
OhDearPingFailedevent, optionally writes a debug log, and rethrows the exception. The queue worker then retries the job according to its normal retry handling, until the job'sretryUntil()deadline:retry_job_for_minutesafter the job was dispatched (default10). After that the job is marked as failed.
The expiry exists because a ping that arrives very late is useless or misleading: Oh Dear would already have flagged the run.
The job also sets $deleteWhenMissingModels = true: if the log item it refers to was deleted before the job ran (for example by pruning, or because a full sync removed the task), the job is discarded silently.
With the default settings, one job attempt that fails completely takes about 20 seconds (three tries with two 10-second pauses). Keep this in mind for the worker's --timeout and when the sync queue driver is used.
Choosing the Queue
| Config key | oh_dear.queue |
|---|---|
| Environment variable | OH_DEAR_QUEUE |
| Default | null (the connection's default queue) |
When set, every ping job is put on that queue (on the default queue connection). A dedicated queue keeps pings from waiting behind slow application jobs, which is the most common cause of false "late" notifications. To use a different connection, use a custom job.
Horizon
| Config key | oh_dear.silence_ping_oh_dear_job_in_horizon |
|---|---|
| Default | true |
Ping jobs run every minute and would flood Horizon's job lists. When Horizon is installed and this option is enabled, the package adds PingOhDearJob to horizon.silenced at boot, unless it is already there.
Note: Only the base class
Spatie\ScheduleMonitor\Jobs\PingOhDearJobis added. If you configure a custom ping job, add your class tosilencedinconfig/horizon.phpyourself.
Custom Ping Endpoints
| Config key | oh_dear.endpoint_url |
|---|---|
| Environment variable | OH_DEAR_PING_ENDPOINT_URL |
| Default | null (use the ping URL returned by Oh Dear) |
When set, the sync builds each task's ping URL as rtrim(endpoint_url, '/') . '/' . uuid instead of using the URL Oh Dear returned. Use it when Oh Dear gives you an alternative ping host, or to route pings through a proxy.
The endpoint is applied during the sync. After changing it, run a full schedule-monitor:sync to rewrite all ping URLs; --keep-old only updates newly registered tasks.
Debug Logging
| Config key | oh_dear.debug_logging |
|---|---|
| Environment variable | OH_DEAR_DEBUG_LOGGING |
| Default | false |
For intermittent timeouts or connection problems, enable detailed diagnostics:
OH_DEAR_DEBUG_LOGGING=true
Each failed job attempt then writes a Log::warning with the message PingOhDearJob failed: <exception message> and this context:
| Context key | Contents |
|---|---|
request.url |
The ping URL |
request.data |
The request body |
request.headers |
The request headers, when available |
exception |
The exception message |
timing |
namelookup_time_s, connect_time_s, appconnect_time_s (TLS), starttransfer_time_s (time to first byte), total_time_s |
connection |
primary_ip, primary_port, local_ip |
response |
status, headers, and body (first 1024 characters), only when a response was received |
The timing and connection data come from cURL's transfer statistics of the last HTTP try. Successful pings are never logged.
The OhDearPingFailed Event
Each failed job attempt dispatches Spatie\ScheduleMonitor\Events\OhDearPingFailed, whether or not debug logging is on. It has four public properties:
| Property | Type | Contents |
|---|---|---|
logItem |
MonitoredScheduledTaskLogItem |
The log item being pinged (with ->monitoredScheduledTask) |
payload |
Payload |
The payload object; url() and data() return the URL and body |
exception |
Throwable |
The exception of the last try, for example a RequestException or ConnectionException |
transferStats |
?GuzzleHttp\TransferStats |
Transfer statistics, only when debug logging is enabled; otherwise null |
Listen to it to report ping problems through your own channels:
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Spatie\ScheduleMonitor\Events\OhDearPingFailed;
public function boot(): void
{
Event::listen(function (OhDearPingFailed $event) {
Log::channel('slack')->warning('Could not ping Oh Dear', [
'task' => $event->logItem->monitoredScheduledTask->name,
'url' => $event->payload->url(),
'error' => $event->exception->getMessage(),
]);
});
}
Because the queue retries the job, the event can fire several times for the same ping.
Using a Custom Ping Job
| Config key | oh_dear.ping_oh_dear_job |
|---|---|
| Default | Spatie\ScheduleMonitor\Jobs\PingOhDearJob |
The class is instantiated with the log item, new $jobClass($logItem), and dispatched. If the config value is empty, the default class is used. Your class should extend PingOhDearJob to keep the ping logic:
namespace App\Jobs;
use Spatie\ScheduleMonitor\Jobs\PingOhDearJob;
use Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem;
class CustomPingOhDearJob extends PingOhDearJob
{
public function __construct(MonitoredScheduledTaskLogItem $logItem)
{
parent::__construct($logItem);
// Send pings through a dedicated Redis connection.
$this->onConnection('redis-monitoring');
}
}
Register it in config/schedule-monitor.php:
'oh_dear' => [
// ...
'ping_oh_dear_job' => \App\Jobs\CustomPingOhDearJob::class,
],
Typical reasons for a custom job: a different queue connection, middleware, tags for Horizon, a different retryUntil(), or extra work after a ping (override handle() and call parent::handle()). Remember to add the custom class to Horizon's silenced jobs and to multitenancy's not_tenant_aware_jobs if you use them.