Run Vercel Cron more than once a day on the Hobby plan
Originally published on RunLater.
On Vercel's Hobby plan a cron job can run at most once a day. A schedule like */15 * * * * fails the deploy with:
Hobby accounts are limited to daily cron jobs. Vercel's docs also say Hobby timing is not precise: the job runs at some point within the hour you set.
The usual fix is to keep your cron logic in a normal API route and have an outside scheduler call that route over HTTP. Any scheduler that can send an authenticated request works. The route side is the same whichever you pick.
1. Protect the route with a secret
Your route is a public URL, so check a bearer token before doing any work:
// app/api/cron/sync/route.ts export async function GET(req: Request) { if (req.headers.get('authorization') !== `Bearer ${process.env.CRON_SECRET}`) { return new Response('Unauthorized', { status: 401 }); } // ... your job return Response.json({ ok: true }); } Add CRON_SECRET to your Vercel project's environment variables and redeploy.
2. Remove the schedule from vercel.json
Delete the crons entry for this route so the deploy no longer fails.
3. Point a scheduler at the route
Whatever you use, set these:
- URL:
https://your-app.vercel.app/api/cron/sync - Method:
GET(orPOSTif your route expects it) - Header:
Authorization: Bearer <your CRON_SECRET> - Schedule: any cron expression, for example
*/15 * * * * - Timezone: yours, so "9am" means your 9am
- Retries: 3 is a good start, so a cold start or a 5xx gets another try
Not sure about the expression? Paste it into a cron expression explainer to see the next run times.
What to expect
Each call still runs as a Vercel function, so it counts toward your Vercel usage like any other request to that route.
If one daily job is all you need, Vercel's built-in cron is free and is the simpler choice.
Disclosure
I work on RunLater, which is one of the schedulers that does this: down to once a minute, with a log of every run's status code, timing and response body. Starter is $15/month after a 14-day trial. There's a side by side at RunLater vs Vercel Cron Jobs, and how it compares with other schedulers.
原文:https://www.a8q9.cn/en/article/run-vercel-cron-more-than-once-a-day-on-the-hobby-plan-698a93.html