How to Monitor Rust Cron Jobs with CronRabbit
RustThe Problem
Rust binaries running on cron can panic, encounter I/O errors, or exit abnormally. Without monitoring, crashes go undetected.
The Solution
Use reqwest or ureq to send an HTTP ping to CronRabbit after successful execution.
Integration
Rust's strong type system helps prevent many bugs, but panics, I/O failures, and environment issues still happen at runtime. Add a CronRabbit ping to verify your job actually completed.
Code Examples
Using ureq (minimal dependencies)
Rustfn main() {
let ping = "https://ping.cronrabbit.com/your-id";
let _ = ureq::get(&format!("{ping}/start")).call();
match run_job() {
Ok(_) => { let _ = ureq::get(ping).call(); }
Err(e) => {
let _ = ureq::get(&format!("{ping}/fail")).call();
eprintln!("Job failed: {e}");
std::process::exit(1);
}
}
}Using reqwest (async)
Rust#[tokio::main]
async fn main() {
let ping = "https://ping.cronrabbit.com/your-id";
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(10))
.build().unwrap();
let _ = client.get(format!("{ping}/start")).send().await;
match run_job().await {
Ok(_) => { let _ = client.get(ping).send().await; }
Err(e) => {
let _ = client.get(format!("{ping}/fail")).send().await;
eprintln!("Failed: {e}");
std::process::exit(1);
}
}
}