Search forkrail

Search documentation, comparisons, and CLI commands.

Cron jobs and schedules

Call your production deployment on a schedule with crons in vercel.json, or with named schedules that have their own time zone, method and jitter.

Define a schedule

vercel.json
{
"crons": [
{ "path": "/api/cron/sync", "schedule": "0 5 * * *" }
],
"schedules": {
"daily-report": {
"schedule": "0 9 * * 1-5",
"path": "/api/report",
"requestMethod": "GET",
"timezone": "America/New_York",
"jitter": 5
}
}
}
  • crons: a GET to path, in UTC, within the minute.
  • schedules: a named schedule with its own IANA timezone (UTC by default), requestMethod (GET or POST, POST by default) and jitter (1 to 15 minutes; the run starts somewhere in that window).
  • Expressions have five fields (minute, hour, day of month, month, day of week with Sunday = 0) using digits, *, ,, - and /. Names like MON aren’t accepted.
  • Up to 100 a project, both keys together. Frameworks that define crons (Nitro 3’s scheduledTasks) are merged in.

Secure the endpoint

The path is public, so check who’s calling. Set a CRON_SECRET environment variable and every run sends Authorization: Bearer <CRON_SECRET>:

api/cron/sync.ts
export function GET(request: Request) {
if (request.headers.get('authorization') !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response('Unauthorized', { status: 401 })
}
// ...do the work
return Response.json({ ok: true })
}

How runs work

  • Only production runs schedules. A deploy, promote or rollback brings the schedules of whichever deployment is production now.
  • Each run is a request to production, logged like any other, with no retries. Redirects aren’t followed and the deployment’s maxDuration applies.
  • Runs that overlap aren’t stopped. A run can (rarely) arrive twice or be skipped, so make the handler safe to run twice.
  • A run that can’t start on time starts late, up to its jitter plus the time between runs; later than that it’s skipped and logged. Monthly and yearly crons never expire.
  • Schedules run on AWS EventBridge Scheduler in your account. Each run costs what a request to your function costs.

Run, pause and resume

forkrail schedules ls my-app # state and next runs (alias: forkrail crons)
forkrail schedules run my-app daily-report # run now, whatever its state
forkrail schedules disable my-app --all # stays off across deploys and rollbacks
forkrail schedules enable my-app daily-report

The dashboard’s Schedules page does the same and lists each schedule’s runs; the Logs page filters by schedule. Everyone on the team can see schedules; members and owners run and change them.

New to forkrail? Install it in your AWS account and deploy your first app in about 20 minutes.
Quickstart