agentleFS
YepAPIYepAPI/skills/skills/cron-jobs/SKILL.md

cron-jobs

Skill8 starsChanged 7 months agoMITView on GitHub

Scheduled tasks with Vercel Cron, Inngest, node-cron, crontab syntax, and error handling.

  • Reads credentials
Files
SKILL.md

Cron Jobs

Rules

  • Vercel Cron: define in vercel.json with { "crons": [{ "path": "/api/cron/task", "schedule": "0 * * * *" }] }
  • Secure cron endpoints: verify Authorization: Bearer ${CRON_SECRET} header — prevent unauthorized invocations
  • Idempotent handlers — cron jobs can fire twice; always check if work was already done
  • Timeout awareness: Vercel functions timeout at 10s (hobby) / 60s (pro) — offload long tasks to queues
  • Inngest for complex scheduling: inngest.createFunction({ id: "...", cron: "0 9 * * *" }, handler)
  • node-cron for self-hosted: cron.schedule("*/5 * * * *", task) — only for persistent servers
  • Crontab syntax: minute hour day month weekday — use https://crontab.guru to verify
  • Log every run with start time, end time, success/failure, items processed
  • Error handling: wrap in try/catch, report failures to logging/alerting, don't let one failure stop the next run

Patterns

// vercel.json
{
  "crons": [
    { "path": "/api/cron/daily-report", "schedule": "0 9 * * *" },
    { "path": "/api/cron/cleanup", "schedule": "0 0 * * 0" }
  ]
}
// Cron route handler
export async function GET(req: Request) {
  const authHeader = req.headers.get("authorization");
  if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
    return new Response("Unauthorized", { status: 401 });
  }

  try {
    const result = await runScheduledTask();
    return Response.json({ success: true, processed: result.count });
  } catch (error) {
    console.error("Cron job failed:", error);
    return Response.json({ success: false, error: String(error) }, { status: 500 });
  }
}

Common Schedules

ScheduleCronDescription
Every hour0 * * * *Top of each hour
Daily 9am UTC0 9 * * *Morning reports
Weekly Sunday0 0 * * 0Cleanup tasks
Every 5 min*/5 * * * *Polling/sync

Avoid

  • Exposing cron endpoints without auth — anyone could trigger them
  • Long-running work inside the handler — offload to a queue for tasks > 10s
  • Assuming exact timing — cron jobs can be delayed; design for idempotency
  • Forgetting error handling — one uncaught error should not break the schedule

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.