How to monitor Rust tokio-cron-scheduler jobs

An async scheduler can stop after a runtime shutdown or a task error. Monitor the work that actually completes.

Report success and failure

Create a check and set PING_URL to its private URL. Replace the example command with your actual task. These examples preserve command failure and do not let a failed reporting request turn a successful job into a failure.

#!/bin/sh
# PING_URL is the private URL copied from your check.
: "${PING_URL:?Set PING_URL first}"
rid="$(date +%s)-$$"
report() { curl -fsS -m 10 --retry 3 "$PING_URL/$1?rid=$rid" >/dev/null 2>&1 || :; }
trap 'code=$?; report "$code"; exit "$code"' EXIT
report start
sleep 1
/app/report

Connect it to Rust tokio-cron-scheduler

Inside an async function, configure the scheduler and keep the runtime alive; import Job and JobScheduler.

let scheduler = JobScheduler::new().await?;
scheduler.add(Job::new_async("0 */5 * * * *", |_id, _lock| Box::pin(async {
    let _ = tokio::process::Command::new("sh")
        .arg("/opt/monitored-job.sh").status().await;
}))?).await?;
scheduler.start().await?;

These are integration fragments for an existing project, not a full application. Set the URL in the job’s environment, keep credentials private and ensure the runtime has the dependencies shown.

Things to watch

tokio-cron-scheduler expressions include seconds; CronPulse uses five fields. The leading 0 is omitted in CronPulse.

The shell examples wait one second between start and work to respect the per-check rate guard. For very short tasks, completion-only pings avoid that delay. A killed process may never send a failure ping; the completion deadline catches the missing run instead.

Test the setup

  1. Run a successful task and confirm the check turns up.
  2. Force a nonzero exit or exception and verify the check turns down.
  3. Stop the scheduler after one success and wait for the expected run plus grace.

Set the schedule to your task’s completion cadence, allowing for runtime and queue delay. Use the cron helper to review your calendar schedule.

Questions about Rust tokio-cron-scheduler

Where should the heartbeat run?
Inside the completed task, after the important work. An async scheduler can stop after a runtime shutdown or a task error. Monitor the work that actually completes.
Which grace period should I use?
Allow for job runtime and scheduler startup delay. CronPulse evaluates deadlines once a minute, so alerts generally follow within about 1–2 minutes after grace ends.
Does this test the result of my work?
No. A success ping proves your command reached the reporting step. Validate output and, for backups, test restoration. Missing completion pings catch stopped or killed jobs.

Platform reference: official Rust tokio-cron-scheduler documentation. Adapt fragments to your installed version.

Give your next job a heartbeat.

20 checks free. No card. Built in Ireland.

Create your first check ↗