Render cron job not running? Find the cause and get alerted

A Render cron job that stops doing its work does not email you. You find out when the data it was meant to produce is missing. Here is how to find the cause and get an alert on the next missed run.

Updated

Short answer

Render schedules cron jobs in UTC, allows only one run at a time, and stops a run after 12 hours. A command that never exits blocks every later run. Check the Runs page, then add a heartbeat ping to the end of the command and alert when it stops arriving.

Monitor your Render cron jobs free

Why a Render cron job stops running

A Render cron job service runs your command on a cron schedule. Most "not running" reports come from one of the behaviours below, all taken from the Render cron job docs.

CauseHow to checkFix
Schedule is in UTCThe job fires at an unexpected hourRender uses UTC for all days and times. Convert your local time, and check the expression in a cron generator
Command never exitsThe latest run on the Runs page is still goingRender delays the next scheduled run until the active run finishes, so one hung run holds back all later runs. Use a command that exits when it is done
Run hit the 12-hour limitA run ended after 12 hoursRender stops an active run after 12 hours. Split the work, or use a workflow or background worker for long tasks
Manual run cancelled a runYou clicked Trigger Run while a run was activeRender cancels the active run, then starts the manual one. Wait for the active run to finish
Build did not change the run you expectedYou pushed code while a run was in progressA new build affects only future runs, not runs already in progress
Wrong commandThe command fails when you run it yourselfThe command can be any valid Linux command or an executable bash script. For a Docker job, Render runs the image ENTRYPOINT and CMD unless you set a Docker Command under Advanced

Render guarantees that at most one run of a cron job is active at a time. A run that comes due during an active run is delayed, not dropped. From the outside that looks like a job that stopped running, because nothing new starts until the stuck run ends.

Check the Runs page

  1. Open the cron job in the Render dashboard and go to the Runs page. It lists the run history and the logs for each run.
  2. Look at the latest run. If it is still active long after it should have finished, the command is hanging.
  3. Open that run's logs for the last line it printed. A stuck run usually stops at an open database connection, an unresolved promise or a network call without a timeout.
  4. Click Trigger Run to start a run by hand, for example to debug. Only do this when no run is active, since it cancels one that is.
  5. Check the Builds page if the job runs old code. Builds only affect future runs.

The Runs page only helps once you think to open it. Render does not tell you when a run hangs.

Add a heartbeat to the command

A heartbeat monitor expects a request to a unique URL on a schedule. Send it as the last step of the job, and you get an alert when it does not arrive. A delayed run, a hung run, a crash and a stopped schedule all end the same way: no ping arrives.

Render accepts an executable bash script as the Command, so put the job and the ping in one. set -euo pipefail stops the script at the first failed step, before the ping. Make the file executable with chmod +x and set the Command to ./scripts/nightly.sh.

scripts/nightly.shShell
#!/bin/bash
set -euo pipefail

node dist/sync.js
node dist/cleanup.js

curl -fsS -m 10 --retry 3 https://heartbeat.uptimeio.com/heartbeat/YOUR_HEARTBEAT_TOKEN > /dev/null

You can also ping from code. This works well when the job already runs in Node and you want the ping to depend on the work finishing.

src/sync.tsTypeScript
async function main(): Promise<void> {
  await syncData();

  // Only reached when syncData() did not throw.
  await fetch(process.env.HEARTBEAT_URL!, { signal: AbortSignal.timeout(10_000) });
}

main().then(
  () => process.exit(0),
  (error) => {
    console.error('job failed', error);
    process.exit(1);
  },
);

Store the heartbeat URL as an environment variable on the cron job service. It works like a password, so keep it out of the repository.

Set it up in UptimeIO

  1. Create a monitor and choose the Heartbeat type.
  2. Set the interval to match the Render schedule, and a grace period longer than your slowest run, because the ping is sent when the job ends.
  3. Copy the heartbeat URL into the cron job's command or an environment variable.
  4. Choose where alerts go: email, Slack, Telegram, Pushover or a webhook.
  • Plans: heartbeat monitors are on every plan, including Free. The shortest interval is 5 minutes on Free and 1 minute on Pro and Scale.
  • Intervals: 1 minute to 24 hours, with a grace period of 1 second to 1 hour.
  • Incidents: an incident opens when a ping is late, and resolves after 3 on-time pings in a row.

Questions

Why is my Render cron job not running?
The most common reasons are a UTC schedule that differs from your local time, or a previous run that never exited. Render allows one run at a time and delays the next scheduled run until the active one finishes. Check the Runs page for a run that is still active.
Does Render skip a cron run if the previous one is still going?
According to the Render docs it delays the next run until the active run finishes, rather than skipping it. A run that hangs therefore holds back every later run until it ends or reaches the 12-hour limit.
How long can a Render cron job run?
Render stops an active run after 12 hours. For longer or continuous work, the Render docs recommend a workflow or a background worker.
How do I get an alert when a Render cron job fails?
The Render cron job docs do not describe failure notifications. Add a request to a heartbeat URL at the end of the command, joined with &&, so it is sent only on success, and alert when it does not arrive.
What time zone do Render cron jobs use?
UTC. Render states that all day and time ranges use UTC, so convert from your local time when you write the schedule.

Related

Start monitoring in a few minutes

Start monitoring free

Free plan · 50 monitors · No credit card required