Monitor Agenda.js Scheduled Jobs with CronRabbit
Node.jsThe Problem
Agenda.js stores jobs in MongoDB, but if MongoDB is down or the worker isn't running, scheduled jobs silently fail to execute.
The Solution
Add CronRabbit pings inside your Agenda job definitions. If a job doesn't run or fails, CronRabbit alerts you.
Agenda.js Monitoring Pattern
Define your job with a CronRabbit ping at completion. Agenda handles scheduling and persistence, CronRabbit handles external verification.
Code Examples
Agenda.js with monitoring
JavaScriptconst Agenda = require("agenda");
const agenda = new Agenda({ db: { address: process.env.MONGO_URL } });
agenda.define("nightly-cleanup", async (job) => {
await fetch("https://ping.cronrabbit.com/your-id/start");
try {
await cleanupExpiredSessions();
await fetch("https://ping.cronrabbit.com/your-id");
} catch (err) {
await fetch("https://ping.cronrabbit.com/your-id/fail");
throw err;
}
});
await agenda.start();
await agenda.every("0 3 * * *", "nightly-cleanup");