Skip to main content

Integrations

The Crontify SDK works with any Node.js job runner. Here are complete examples for the most common ones.

node-cron​

import cron from 'node-cron';
import { CrontifyMonitor } from '@crontify/sdk';

const monitor = new CrontifyMonitor({
apiKey: process.env.CRONTIFY_API_KEY!,
monitorId: process.env.CRONTIFY_MONITOR_ID!,
});

// Using wrap() — recommended
cron.schedule('0 9 * * *', async () => {
await monitor.wrap(async () => {
await sendDailyDigestEmails();
});
});

// Manual pings with metadata
cron.schedule('*/5 * * * *', async () => {
await monitor.start();
try {
const result = await syncInventory();
await monitor.success({
meta: { rows_synced: result.count },
});
} catch (error) {
await monitor.fail({
message: error instanceof Error ? error.message : 'Sync failed',
log: error instanceof Error ? error.stack : undefined,
});
}
});

BullMQ​

import { Worker } from 'bullmq';
import { CrontifyClient } from '@crontify/sdk';

const crontify = new CrontifyClient({
apiKey: process.env.CRONTIFY_API_KEY!,
});

const worker = new Worker(
'report-queue',
async (job) => {
const monitor = crontify.monitor(process.env.CRONTIFY_REPORT_MONITOR_ID!);

await monitor.wrap(async () => {
await generateWeeklyReport(job.data);
});
},
{ connection: { host: 'localhost', port: 6379 } },
);

Agenda​

import Agenda from 'agenda';
import { CrontifyMonitor } from '@crontify/sdk';

const agenda = new Agenda({ db: { address: process.env.MONGODB_URL! } });

const invoiceMonitor = new CrontifyMonitor({
apiKey: process.env.CRONTIFY_API_KEY!,
monitorId: process.env.CRONTIFY_INVOICE_MONITOR_ID!,
});

agenda.define('send monthly invoices', async () => {
await invoiceMonitor.wrap(async () => {
const customers = await getActiveSubscribers();
await Promise.all(customers.map((c) => sendInvoice(c)));
});
});

agenda.every('1 month', 'send monthly invoices');
await agenda.start();

Inngest​

import { inngest } from './inngest-client';
import { CrontifyMonitor } from '@crontify/sdk';

const monitor = new CrontifyMonitor({
apiKey: process.env.CRONTIFY_API_KEY!,
monitorId: process.env.CRONTIFY_CLEANUP_MONITOR_ID!,
});

export const cleanupJob = inngest.createFunction(
{ id: 'cleanup-expired-sessions' },
{ cron: '0 2 * * *' },
async ({ step }) => {
await monitor.wrap(async () => {
await step.run('delete-expired-sessions', async () => {
await deleteExpiredSessions();
});
});
},
);

setInterval (plain async)​

import { CrontifyMonitor } from '@crontify/sdk';

const monitor = new CrontifyMonitor({
apiKey: process.env.CRONTIFY_API_KEY!,
monitorId: process.env.CRONTIFY_HEALTH_CHECK_MONITOR_ID!,
});

setInterval(async () => {
await monitor.wrap(async () => {
const status = await checkExternalApiHealth();
if (!status.ok) {
throw new Error(`API unhealthy: ${status.reason}`);
}
});
}, 5 * 60 * 1000);

Shell script (curl)​

For jobs that aren't written in Node.js, you can send pings directly with curl. See HTTP Integration for the full endpoint reference.

#!/bin/bash

API_KEY="ck_live_..."
MONITOR_ID="clxxx..."
BASE_URL="https://api.crontify.com/api/v1"

# Signal start
curl -s -X POST "$BASE_URL/ping/$MONITOR_ID/start" \
-H "X-API-Key: $API_KEY"

# Run the job and capture output
JOB_OUTPUT=$(python3 /path/to/job.py 2>&1)
EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
curl -s -X POST "$BASE_URL/ping/$MONITOR_ID/success" \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{\"meta\": {\"exit_code\": 0}}"
else
# Escape and attach log output
ESCAPED_LOG=$(echo "$JOB_OUTPUT" | python3 -c "import json,sys; print(json.dumps(sys.stdin.read()))")
curl -s -X POST "$BASE_URL/ping/$MONITOR_ID/fail" \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{\"errorMessage\": \"Exited with code $EXIT_CODE\", \"logOutput\": $ESCAPED_LOG}"
fi