Add a heartbeat
A heartbeat tells you when a scheduled job stops running. You create it in Alopex, then add one call to your job that pings its URL when the job finishes. How Alopex judges the pings is explained in About heartbeat checks.
Before you start
- A domain on your account. The heartbeat belongs to a domain.
- Permission to edit that domain.
- A free heartbeat on your plan. Your plan sets how many you can have across your account. When you reach the limit, Add check shows how many your plan includes, with a link to upgrade. You can also delete a heartbeat you no longer need, because the count is of the heartbeats you have. See Plans and limits and pricing.
- A scheduled job on a machine that can make outbound
httpsrequests.
Create the heartbeat
- Open the domain and select the Checks tab.
- Select Add check, then Heartbeat. Add a check covers the other types.
- In Name, enter a name for the job, such as
Nightly backup. - In Expected every (minutes), enter how often the job runs. For a daily job, enter
1440. - In Grace period (minutes), enter how late a ping can be before it counts as missed. The default is
5. - Select Create heartbeat.
You return to the Checks tab. The heartbeat is listed in the Heartbeat card, with its status as Pending until the first ping arrives and a Heartbeat ping URL beside it.
Copy the ping URL
Select Copy next to Heartbeat ping URL. The URL has this form:
https://et.alopex.uk/<token>
The token is 40 letters and digits. Copy the URL from Alopex rather than typing it. Anyone who has it can ping the heartbeat, so keep it out of public repositories and logs you share.
Call the URL from your job
Call the URL as the last step of the job, and only if the job succeeded. Use GET or POST. Choose the example that matches how your job runs. Each uses https://et.alopex.uk/<token>, so replace <token> with your own.
From cron
This crontab line runs a backup at 03:00 every day. The && means curl runs only if the backup exits successfully.
0 3 * * * /usr/local/bin/backup && curl -fsS -m 10 --retry 3 https://et.alopex.uk/<token> > /dev/null
The curl options make it fail on an error response (-f), stay quiet unless it fails (-sS), give up after 10 seconds (-m 10) and retry up to three more times if the request fails with a temporary error (--retry 3).
From a shell script
#!/usr/bin/env bash set -euo pipefail /usr/local/bin/backup curl -fsS -m 10 --retry 3 -o /dev/null https://et.alopex.uk/<token>
Because of set -e, the script stops if the backup fails, and the ping is never sent.
From the Laravel scheduler
In routes/console.php, add pingOnSuccess to the scheduled command:
<?php
use Illuminate\Support\Facades\Schedule;
Schedule::command('backup:run')
->dailyAt('03:00')
->pingOnSuccess('https://et.alopex.uk/<token>');
Laravel calls the URL after the command succeeds. The scheduler itself must be running, with this crontab entry on the server:
* * * * * cd /path/to/your-app && php artisan schedule:run >> /dev/null 2>&1
If that entry stops running, no scheduled command runs and no ping is sent, which is exactly what a heartbeat is there to show.
Check that it worked
Run the job once, or send a ping by hand:
curl -fsS https://et.alopex.uk/<token>
A recorded ping answers
OK.On the Checks tab, the heartbeat's status changes from Pending to Up, and its last-seen time shows the ping instead of Never.
If the answer is Ignored, the heartbeat is paused, its domain is switched off, or the account is suspended. If it is not found, check the token. See My heartbeat was missed if an alert arrives later.
Next steps
- Change how often the job is expected, or its grace period, in Heartbeat check settings.
- Pause the heartbeat or cover it with a maintenance window when you expect the job to stop. Both are described in About heartbeat checks.