Monitor Heroku Scheduler jobs

On this page

Heroku says it plainly: Scheduler job execution is expected but not guaranteed, and a job may occasionally be skipped. If a scheduled task matters, add a ping so that the rare skipped run becomes an alert instead of a surprise.

How can a scheduled job fail silently on Heroku Scheduler?

  • Heroku documents that Scheduler is known to occasionally, but rarely, miss the execution of scheduled jobs, and recommends a custom clock process when scheduled jobs are critical.
  • Jobs run as one-off dynos. A dyno started by the Scheduler does not run longer than its scheduling interval, so a job set to every 10 minutes is terminated after about 10 minutes.
  • The dashboard offers three frequencies: every 10 minutes, every hour, or every day at a set time. There is no way to say "weekdays only" or "the first of the month" without code that checks the date.
  • Daily jobs are set in UTC, so a "midnight" job runs at a different local time after a daylight saving change.

What are the limits of Heroku Scheduler?

LimitWhat the documentation says
FrequenciesEvery 10 minutes, every hour or every day at a chosen time.
Time zoneThe next run time of a daily job is in UTC.
Run timeA scheduled dyno is stopped after about its scheduling interval.
BillingScheduler is a free add-on, but its one-off dynos count toward the monthly dyno usage.
ReliabilityExecution is expected but not guaranteed; a run is occasionally skipped.

How do you add a CronMissed ping to Heroku Scheduler?

Put the ping in the command you give the Scheduler, after the task. Because the Scheduler stops the dyno near the end of its interval, keep the task and the ping well inside that time.

Heroku Scheduler command
rake nightly:cleanup && curl -fsS --max-time 10 --retry 3 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10

To report failures as well, use a small script as the command and send the exit status.

bin/scheduled-cleanup
#!/bin/sh
curl -fsS --max-time 10 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10/start
rake nightly:cleanup
status=$?
curl -fsS --max-time 10 --retry 3 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10/$status
exit $status

Which check settings fit Heroku Scheduler?

Use a simple check whose period matches the Scheduler frequency (600 seconds for every 10 minutes, 3600 for hourly, 86400 for daily) and a generous grace, since Heroku may start a job late. A grace of 15 minutes on an hourly or daily job is sensible. For the daily job use a cron check in UTC if you want the exact time watched.

How do you confirm the check works?

  1. Use the "Add job" dialog to set the job to every 10 minutes, wait for one run, and confirm the ping.
  2. Change the task to one that fails and confirm the check goes down immediately with the status.
  3. Remove the job from the dashboard and confirm that the check goes late and then down.

Sources

Questions and answers

Is a custom clock process better than the Scheduler?
Heroku itself suggests a clock process for critical jobs, since it gives more control and visibility. Either way, a heartbeat check is the independent witness: it tells you when the scheduler, of either kind, did not run.
Will the ping count as extra dyno time?
The curl runs inside the same one-off dyno as the task and takes a fraction of a second, so it adds almost nothing to the dyno time you already pay for.
Know when this job stops

Create a check, add the ping to the job, and CronMissed alerts you the first time a run is late or reports a failure.

Start monitoring