Get up and running with cronhost in under 5 minutes
curl -X POST "https://cronho.st/api/v1/schedules" \ -H "x-api-key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Hourly Health Check", "description": "Check if our API is healthy every hour", "cronExpression": "0 * * * *", "timezone": "UTC", "endpoint": "https://api.example.com/health", "httpMethod": "GET", "maxRetries": 3, "timeoutSeconds": 30 }'
npm install cronhost
import { Cronhost } from "cronhost"; const cronhost = new Cronhost({ apiKey: "YOUR_API_KEY", }); const schedule = await cronhost.createSchedule({ name: "Hourly Health Check", description: "Check if our API is healthy every hour", cronExpression: "0 * * * *", timezone: "UTC", endpoint: "https://api.example.com/health", httpMethod: "GET", maxRetries: 3, timeoutSeconds: 30, }); console.log("Schedule created:", schedule.id);
┌───────────── minute (0 - 59) │ ┌───────────── hour (0 - 23) │ │ ┌───────────── day of month (1 - 31) │ │ │ ┌───────────── month (1 - 12) │ │ │ │ ┌───────────── day of week (0 - 7) (Sunday=0 or 7) │ │ │ │ │ * * * * *
0 9 * * *
*/15 * * * *
0 0 * * 0
0 12 1 * *
30 14 * * 1-5
// Examples of timezone usage const schedule = await cronhost.createSchedule({ name: "East Coast Business Hours", cronExpression: "0 9 * * 1-5", // Weekdays at 9 AM timezone: "America/New_York", // Handles EST/EDT automatically endpoint: "https://api.example.com/check", });
curl -H "x-api-key: YOUR_API_KEY" \ "https://cronho.st/api/v1/schedules/SCHEDULE_ID"
curl -H "x-api-key: YOUR_API_KEY" \ "https://cronho.st/api/v1/jobs?scheduleId=SCHEDULE_ID&limit=10"
// Get schedule details const schedule = await cronhost.getSchedule("SCHEDULE_ID"); console.log("Next run:", schedule.nextRunAtUtc); // Get recent jobs const jobs = await cronhost.getJobs({ scheduleId: "SCHEDULE_ID", limit: 10, }); jobs.forEach((job) => { console.log(`Job ${job.id}: ${job.status} - ${job.completedAtUtc}`); });
const healthCheck = await cronhost.createSchedule({ name: "API Health Monitor", cronExpression: "*/5 * * * *", // Every 5 minutes timezone: "UTC", endpoint: "https://your-api.com/health", httpMethod: "GET", maxRetries: 2, timeoutSeconds: 10, });
const weeklyReport = await cronhost.createSchedule({ name: "Weekly Report Webhook", cronExpression: "0 9 * * 1", // Every Monday at 9 AM timezone: "America/New_York", endpoint: "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK", httpMethod: "POST", body: JSON.stringify({ text: "Weekly report is ready for review!", }), headers: { "Content-Type": "application/json", }, });
const dailyBackup = await cronhost.createSchedule({ name: "Daily Database Backup", cronExpression: "0 2 * * *", // Every day at 2 AM timezone: "UTC", endpoint: "https://your-api.com/backup/trigger", httpMethod: "POST", headers: { Authorization: "Bearer YOUR_TOKEN", }, maxRetries: 1, timeoutSeconds: 300, // 5 minutes for longer operations });
const updated = await cronhost.updateSchedule("SCHEDULE_ID", { cronExpression: "0 */2 * * *", // Change to every 2 hours maxRetries: 5, });
// Disable schedule await cronhost.toggleSchedule("SCHEDULE_ID", false); // Re-enable later await cronhost.toggleSchedule("SCHEDULE_ID", true);
// Trigger immediately for testing const job = await cronhost.triggerSchedule("SCHEDULE_ID"); console.log("Triggered job:", job.id);
try { const schedule = await cronhost.createSchedule({ // ... schedule data }); console.log("Success!", schedule.id); } catch (error) { console.error("Failed to create schedule:", error.message); // Check for specific error types if (error.message.includes("Invalid cron expression")) { console.log("Please check your cron syntax"); } }