Skip to content
Oh Dear
Docs/Features

Set up heartbeat monitoring in your app (guide by language)

Looking for what cron job monitoring does and why? Start on the feature page; this guide covers the setup.

Cron job monitoring uses an industry-standard way of monitoring the health of your scheduled tasks. We use a callback URL, sometimes called a heartbeat or pingback.

When you create a cron job definition in Oh Dear, you will be given a unique URL specific to that cron job.

You can then modify your cron job in your code or on your servers, to do a quick network fetch to that unique URL. If we receive that pingback on time, we know the cron job was executed correctly.

If we don't receive a hit on that unique URL, we know the cron job hasn't been executed, and we can alert you.

Tip: Don't want to set this up by hand? On your monitor's Scheduled tasks tab (and under its Settings), Oh Dear gives you a ready-made AI prompt. Paste it into your AI coding assistant (Claude Code, Cursor, ...) and it will sync your whole schedule and wire up the pings for you, in any language or framework.

Amount of cron jobs to monitor #

Per website in your subscription package, you have a quota of 10 cron jobs you can monitor.

For instance: if you are currently on the 10-site plan, you will have a total quota of 100 cron jobs you can monitor.

You are free to use those any way you like, you can add 90 cron jobs to a single monitor and the remaining 10 cron jobs to another one. To monitor more cron jobs, you can upgrade your subscription.

Simple cron job monitoring #

By default, we have the option to do simple cron job monitoring. It gives you heartbeat alerts when a job is late, as a product.

For simple cron job monitoring, you would only need to provide the frequency. In other words, how often does this cron job run on your systems?

This would be set to the exact frequency the scheduled tasks are executed. If a cron job runs every five minutes, you would set the frequency to 5.

Cron expression monitoring #

New to the syntax? See what a cron expression is first.

An alternative to the simple cron job monitoring is the method where you define a crontab schedule instead.

To use this, you can enter the exact crontab syntax you would find on your servers. For instance, for cron expression type monitoring, you could enter the following:

  • * * * * *: this would run every minute
  • */5 * * * *: this would run every five minutes
  • 0 */4 * * *: this would run every 4 hours
  • 0 10 1 * *: this would run at 10AM on the first day of each month

While the syntax is more arcane (it's default crontab syntax), it allows you to copy/paste directly from your crontab.

Server Timezone #

If you're using the cron expression to define your cron job monitors, we need to know the timezone of your server. It's that timezone that determines when the scheduled tasks will be executed.

Not sure what timezone your server is configured in? You can find out here.

Grace time #

What's the grace time in cron job monitoring? It defines how much time should we allow for a pingback to be received.

To understand this option better, consider the following example.

  1. You have a cron job that runs every 5 minutes.
  2. Sometimes, the cron job finishes in a matter of seconds. Sometimes it takes a few minutes to complete, as it has to import data or calculate results.

Because the cron job is executed every five minutes, the frequency option would be set to 5.

Because there's a variable execution time in the cron job, we want to allow a bit more time for the cron job to actually finish and report back to us. If you know the job itself should not take more than two minutes to complete, you could set the grace time to 3 - slightly higher than your maximum execution time.

This gives us a little more wiggle room before we send out a notification.

In this example, if the cronjob isn't executed, we will wait for 3 more minutes before we send the notifications. If we receive the ping that the cron was executed during that grace time, we won't send any notifications. The feature page explains what the paid check alerts on, and when.

Implementing the Ping URL in your application #

In order to use your cron job monitoring, your application should be configured to make an HTTP call to the Ping URL whenever the job is completed. Here are some ways you could implement this.

We have example code available for:

We have support for even more advanced options, like providing runtime duration and memory usage or failure states. Have a look at the advanced options & parameters to see what's possible.

Crontab #

Oh Dear users can add cron job monitoring to any existing crontab on your Linux servers. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing crontab.

Example crontab monitoring #

Imagine you have the following cronjob configured on your Linux server.

$ crontab -l
55 * * * * script.sh

You can modify this line so it calls back to our Ping URL whenever your script has executed successfully.

$ crontab -l
55 * * * * script.sh && curl -fsS --retry 3 -o /dev/null https://ping.ohdear.app/e536e771-9ff6

By using the && operation in Bash, we will only call our URL if your script finished with an exit code of 0. In other words: we'll only call our URL if your script executed without any error.

Note: make sure your script throws a non-zero exit code whenever it has encountered a failure condition.

Example script monitoring in Bash #

Alternatively, if you are calling a Bash script in your crontab, you can move the curl call to the very last line of your Bash script instead. If curl is not available on your system, you may also use wget.

curl --retry 3 https://ping.ohdear.app/e536e771-9ff6
wget -O /dev/null https://ping.ohdear.app/e536e771-9ff6

This allows you to implement cron job monitoring to any Bash script, regardless of how it's being called.

Advanced use of cron job reporting #

Next to providing us a ping whenever your script has finished, you can also actively send failure states to us.

For more information about sending failures or debug-information like memory consumption & runtime duration, please see the advanced options of our cron job monitoring.

PHP #

Oh Dear users can add cron job monitoring to any existing PHP script. When you create a cronjob monitor in your account, you're given a unique pingback URL that should be called every time a script completes.

In this guide, we'll cover how you can implement that in your existing PHP code.

Cron monitoring in generic PHP #

This is a technique that can be used in any PHP application, regardless of the framework you use.

At the very bottom of your scheduled command, add a call to the file_get_contents() function that will call back to us and inform you the job has ended.

@file_get_contents('https://ping.ohdear.app/e536e771-9ff6');

Note: make sure your script stops executing on error conditions, so the file_get_contents() function isn't called even if the script has failed.

Cron monitoring in Laravel (PHP) #

Using Laravel Rust or Laravel Go? Follow the Laravel Rust setup or Laravel Go setup below instead.

Note: there's a convenient Laravel package called spatie/laravel-schedule-monitor you can use that syncs up nicely with Oh Dear. Please refer to this package's documentation on how it works.

In standard Laravel, you can use the thenPing() method in your Console scheduler. In Laravel 11+, you'll find this in the routes/console.php file.

// In routes/console.php (Laravel 11+)
use Illuminate\Support\Facades\Schedule;

Schedule::command('emails:send')
    ->daily()
    ->thenPing('https://ping.ohdear.app/e536e771-9ff6');

Cron monitoring in Symfony (PHP) #

This example uses the zenstruck/schedule-bundle scheduler in Symfony.

You can either define it in your PHP code:

use Zenstruck\ScheduleBundle\Schedule\Task\PingTask;

/* @var \Zenstruck\ScheduleBundle\Schedule $schedule */

$schedule->add(new PingTask('https://ping.ohdear.app/e536e771-9ff6'));

Or in your configurations:

# config/packages/zenstruck_schedule.yaml
zenstruck_schedule:
  tasks:
    # note the "ping:" prefix
    - task: ping:https://ping.ohdear.app/e536e771-9ff6
      frequency: '0 * * * *'

Laravel Rust #

For Laravel Rust applications, use spatie/laravel-schedule-monitor-rust, the Rust port of the PHP package above. Version 0.1.0 requires Rust 1.99 or newer and Laravel Rust 0.1.0.

Installing the Rust schedule monitor #

Add spatie-laravel-schedule-monitor from crates.io to your Cargo.toml, selecting your application's database driver:

[dependencies.spatie-laravel-schedule-monitor]
version = "0.1.0"
default-features = false
features = ["database-mysql"]

Use database-postgres or database-sqlite instead if that's what your application uses. The package uses your application's default database connection.

Registering scheduled tasks in Rust #

Define each monitored task and attach it to your Laravel schedule. Add the service provider to your application's bootstrap:

use laravel::Application;
use spatie_schedule_monitor::{
    MonitoredTask, OhDear, ScheduleMonitor, service_provider,
};

let cleanup = MonitoredTask::new("cleanup", "0 2 * * *")?
    .timezone("Europe/Brussels")?
    .grace_minutes(10);

let monitor = ScheduleMonitor::new([cleanup.clone()])?
    .oh_dear(OhDear::new(
        "https://ohdear.app/api",
        std::env::var("OH_DEAR_API_TOKEN")?,
    )?)
    .queue_pings();

let builder = Application::configure()
    .with_providers(|providers| {
        providers.add(service_provider(monitor.clone()));
    })
    .with_schedule(move |schedule, _| {
        cleanup.register(schedule.command("app:cleanup"))
            .without_overlapping();
    });

This snippet extends your application's builder. Register your own app:cleanup command with Laravel's console before scheduling it, or replace it with an existing command. Each schedule needs a unique monitor name. Use a shared lock-capable cache for without_overlapping() when more than one scheduler can run the task.

OH_DEAR_API_TOKEN is an environment variable chosen for this example. Set it to an Oh Dear API token that can access your monitor. The Rust package doesn't read the PHP package's configuration or environment keys automatically; the example passes the token to OhDear::new explicitly. Make it available to the application process before building the monitor.

In an application-context database migration, call monitor.migrate().await? using the same monitor definition. Registering the provider doesn't create the tables. See the package's installation and usage guides for database setup and custom table names, including when migrating an app with existing PHP monitor tables.

Syncing Rust tasks with Oh Dear #

Run these commands through your application's Laravel console after migrating. Replace 123 with your Oh Dear monitor ID:

schedule-monitor:sync
schedule-monitor:sync --oh-dear 123 --keep-old
schedule-monitor:verify --oh-dear 123

The first command syncs the local task definitions. The second registers missing checks at Oh Dear and saves their ping URLs without deleting existing remote checks. The last command checks Oh Dear connectivity and the health of the local tasks.

Important: schedule-monitor:sync --oh-dear 123 without --keep-old replaces that monitor's remote checks and can delete checks that aren't in your Rust registry. Only use it when this application owns the monitor's entire schedule. --keep-old only registers tasks that haven't been registered remotely yet; it doesn't update existing remote definitions.

Configure your host to run Laravel's schedule:run every minute. The .queue_pings() call enables automatic ping jobs, but you must also configure a non-sync queue connection, for example QUEUE_CONNECTION=database, and run Laravel's queue:work process. For a database queue, create Laravel's queue tables as well as the monitor tables. Without a worker, queued pings won't reach Oh Dear. A sync queue delivers pings inline instead.

For custom delivery, retries, and pruning old logs, see the package's Monitoring and Oh Dear guide.

Laravel Go #

For Laravel Go applications, use spatie/laravel-schedule-monitor-go, the Go port of the PHP package above. Version v0.1.0 requires Go 1.27 or newer and Laravel Go v0.1.0.

Installing the Go schedule monitor #

Install the Go module:

go get github.com/spatie/laravel-schedule-monitor-go@v0.1.0

Add the package to the existing laravel.Options in bootstrap/app.go, and register tasks in your application's native schedule:

import (
    "context"
    "time"

    schedulemonitor "github.com/spatie/laravel-schedule-monitor-go"
    laravel "go.laravel.com"
    "go.laravel.com/schedule"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{
            schedulemonitor.New(func(cfg *schedulemonitor.Config) {
                grace := 10 * time.Minute
                cfg.Tasks["daily-report"] = schedulemonitor.TaskOptions{
                    Grace: &grace,
                }
            }),
        },
        Schedule: func(ctx context.Context, s *schedule.Schedule) {
            s.Command("reports:generate").Name("daily-report").Daily()
        },
    }
}

Keep any other packages and options your application already uses. Register your own reports:generate command or replace it with an existing command. Each task needs a unique name. The package reads the native schedule, so you don't need a separate task registry. This example allows 10 minutes for the daily task to finish.

Register your application's database driver and configure DATABASE_URL. Package registration adds the monitor's migrations. Run them through your application's console:

go run . migrate

The Go package uses its own database schema. Don't reuse the PHP or Rust monitor tables. See the package's installation guide for custom tables and migrations.

Syncing Go tasks with Oh Dear #

Add these settings to your application's .env file. Replace 123 with your Oh Dear monitor ID and use an Oh Dear API token that can access it:

OH_DEAR_API_TOKEN=replace-with-your-oh-dear-api-token
OH_DEAR_MONITOR_ID=123
OH_DEAR_QUEUE=monitoring

The package reads these environment variables automatically. After migrating, verify the connection and register your tasks:

go run . schedule-monitor:verify
go run . schedule-monitor:sync --keep-old
go run . schedule-monitor:list

schedule-monitor:list shows task status, execution timestamps, and which tasks are registered with Oh Dear. Run sync after deployments that change your schedule.

Important: Without --keep-old, sync removes obsolete local tasks and their logs, and replaces the selected monitor's remote checks. This can delete checks outside your Go application. Only do this when the application owns the monitor's entire schedule. --keep-old only registers new remote checks. It doesn't update existing remote definitions or delete remote checks.

Run Laravel's schedule:work process under your process supervisor. Schedule times are UTC in Laravel Go v0.1.0, and sub-minute schedules aren't supported by the monitor.

Pings use native queued jobs. Configure a non-sync queue connection, for example QUEUE_CONNECTION=database, and run a worker for the monitoring queue:

go run . queue:work --queue=monitoring

For a database queue, add Laravel's queue.CreateTables migration as well as the monitor migrations. Without a worker, queued pings won't reach Oh Dear. A sync queue sends pings inline instead. A dedicated monitoring queue avoids false alerts caused by other jobs delaying delivery.

For task exclusions, retries, pending pings, and pruning old logs, see the package's usage and Monitoring and Oh Dear guides.

Python #

Oh Dear users can add cron job monitoring to any existing Python script. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing Python code.

Cron job monitoring in generic Python #

You can use the requests library in Python to make an outgoing HTTPs call to our Ping URL.

import requests

requests.get("https://ping.ohdear.app/e536e771-9ff6")

Note: make sure your script stops executing on error conditions, so the requests.get function isn't called even if the script has failed.

Ruby #

Oh Dear users can add cron job monitoring to any existing Ruby script. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing Ruby code.

Cron job monitoring in generic Ruby #

Here's how you can add the Ping URL to any existing Ruby script.

require 'net/http'
require 'uri'

Net::HTTP.get(URI.parse('https://ping.ohdear.app/e536e771-9ff6'))

Note: make sure your script stops executing on error conditions, so the Net::HTTP.get function isn't called even if the script has failed.

NodeJS #

Oh Dear users can add cron job monitoring to any existing NodeJS script. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing NodeJS code.

Cron job monitoring in generic NodeJS #

You can use the built-in functions from https to make outgoing network calls.

var https = require('https');
https.get("https://ping.ohdear.app/e536e771-9ff6");

Note: make sure your script stops executing on error conditions, so the https.get function isn't called even if the script has failed.

Perl #

Oh Dear users can add cron job monitoring to any existing Perl script. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing Perl code.

Cron job monitoring in generic Perl #

You can make use of the LWP::Simple library for making network calls.

use LWP::Simple;
get("https://ping.ohdear.app/e536e771-9ff6");

Note: make sure your script stops executing on error conditions, so the get function isn't called even if the script has failed.

Golang #

Oh Dear users can add cron job monitoring to any existing Golang script. When you create a cronjob monitor in your Oh Dear account, you're given a unique pingback URL that should be called every time a cronjob completes.

In this guide, we'll cover how you can implement that in your existing Golang code.

Cron job monitoring in generic Golang #

You can make use of the net/http library for making network calls.

package main

import (
  "fmt"
  "log"
  "net/http"
)

func main() {
    _, err := http.Get("https://ping.ohdear.app/e536e771-9ff6")

    if err != nil {
        log.Println("Couldn't ping Oh Dear endpoint")
    }
}

Note: make sure your script stops executing on error conditions, so the http.Get function isn't called even if the script has failed.

Advanced usage #

We aim to keep our cron job monitoring as simple to use as possible, but that doesn't mean we don't support some more advanced usage cases.

View our scheduled task API documentation for creating, retrieving and syncing tasks from any application.

Bypassing CDNs or caching layers #

Our default usage suggests using a GET method to ping your cron URL, to let us know your cron job ran on time. In some cases, this may not work as intended because of proxies or middleware between your servers and our endpoint.

If you have a caching layer in between, subsequent GET calls may be returned by your proxy instead of our system, and we'd never see the pingback.

If that is the case, you can modify your code to perform a POST call to us, instead. This can be done as follows:

curl -X POST --retry 3 https://ping.ohdear.app/e536e771-9ff6

Note the addition of the -X POST parameter.

Any proxy or caching layer should always let POST calls be sent to our endpoint, these should never be cached.

Providing memory usage, script duration and exit codes #

Our Ping URL has support for providing the total memory consumption and the duration of your script, as optional parameters.

To send this data along, you can change the pingback URL to a POST call with a payload of memory, runtime, exit_code or failure_message formatted as a plain form submission.

That sounds complex, so here's an example implemented in curl:

$ curl -X POST https://ping.ohdear.app/e536e771-9ff6 \
    -F 'memory=29360128' \
    -F 'runtime=0.25' \
    -F 'exit_code=0' \
    -F 'failure_message="Everything ran successfully (exit_code = 0)"'

You provide the form fields using the -F option parameter to curl.

The data should be provided as:

  • memory: numeric, the total memory consumption of your cron job, measured in bytes (in the example above, the script used 28MB of memory)
  • runtime: numeric, the total duration of your cron job, measured in seconds (in this example: 0.25 seconds)
  • exit_code: numeric, the exit code of your script. A value of 0 means your script executed successfully.
  • failure_message: string, a text-version (human readable) for why the script has failed. This can be your debug information. Max 255 characters.

You can choose to pass along just one of these items or all of them at once:

$ curl -X POST https://ping.ohdear.app/e536e771-9ff6 \
    -F 'memory=29360128' \
    -F 'runtime=0.25'

Every payload field is entirely optional.

Starting and finishing jobs #

We also support /starting and /finished tasks to help identify issues and runtime without sending additional POST parameters.

A starting ping will not reset your fixed frequency or cron-based check period. Start and finish pings are part of scheduled-task monitoring on every plan.

Providing active callbacks for failure states #

Our default method of operating is to send you a notification when we have not received a pingback to your unique URL on time.

There are 2 ways you can provide an active callback to us that report the cron job has failed.

This has the benefit that we don't have to wait for the frequency or grace time to expire, we can fire notifications directly when we receive a failure confirmation from your scripts.

Reporting failure via a simple GET call #

Every ping URL you see in your Oh Dear account can have the /failed path appended to it.

If that URL receives a ping, we consider it a confirmation from your end that your script has failed and we'll send out the alert to your notification channels.

Take this as an example:

curl https://ping.ohdear.app/e536e771-9ff6/failed

By adding the /failed path to the end of the ping URL, you can confirm us that this particular cron job has failed.

You can also optionally make this a POST call with the same meta data as runtime, memory and failure_message.

$ curl -X POST https://ping.ohdear.app/e536e771-9ff6/failed \
    -F 'memory=29360128' \
    -F 'runtime=0.25' \
    -F 'exit_code=3' \
    -F 'failure_message="Oh Dear, something went wrong"'

These extra parameters are entirely optional.

Reporting failure with details through a POST call #

You can also perform a POST call to your endpoint with a non-zero exit_code to let us know your script has failed.

This way, you can do a pingback to us and use the exit-code in your script to let us know the state of your cron jobs. Additionally, you can provide memory and runtime information as well (see above).

To do so, implement the following API call to your pingback URL.

$ curl -X POST https://ping.ohdear.app/e536e771-9ff6 \
    -F 'exit_code=1'

The exit_code parameter should be an integer (numeric) value. A value of 0 means the script exited correctly, and we interpret that as a success state.

Any non-zero value submitted back to us will be interpreted as a failed job, and will lead to notifications being sent.

Was this page helpful?

Feel free to reach out via support@ohdear.app or on X via @OhDearApp if you have any other questions. We'd love to help!