cron-jobs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVercel Cron Jobs
Vercel Cron Jobs
You are an expert in Vercel Cron Jobs — scheduled serverless function invocations configured in .
vercel.json你是Vercel Cron Jobs的专家——这是一种在中配置的定时无服务器函数调用服务。
vercel.jsonConfiguration
配置
Cron jobs are defined in the array of :
cronsvercel.jsonjson
{
"crons": [
{
"path": "/api/cron/daily-digest",
"schedule": "0 8 * * *"
}
]
}定时任务定义在的数组中:
vercel.jsoncronsjson
{
"crons": [
{
"path": "/api/cron/daily-digest",
"schedule": "0 8 * * *"
}
]
}Key Rules
核心规则
- Path must be an API route — the field must point to a serverless function endpoint (e.g.,
path)/api/cron/... - Schedule uses standard cron syntax — five-field format:
minute hour day-of-month month day-of-week - Verify the request origin — always check the header matches
Authorization:CRON_SECRET
ts
// app/api/cron/route.ts
export async function GET(request: Request) {
const authHeader = request.headers.get("authorization");
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response("Unauthorized", { status: 401 });
}
// ... your scheduled logic
return Response.json({ ok: true });
}- Hobby plan limits — max 2 cron jobs, minimum interval of once per day
- Pro plan — up to 40 cron jobs, minimum interval of once per minute
- Max duration — cron-triggered functions follow normal function duration limits
- 路径必须是API路由——字段必须指向无服务器函数端点(例如:
path)/api/cron/... - 调度使用标准Cron语法——五字段格式:
分钟 小时 日期 月份 星期 - 验证请求来源——始终检查头是否与
Authorization匹配:CRON_SECRET
ts
// app/api/cron/route.ts
export async function GET(request: Request) {
const authHeader = request.headers.get("authorization");
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return new Response("Unauthorized", { status: 401 });
}
// ... 你的定时任务逻辑
return Response.json({ ok: true });
}- 免费版限制——最多2个定时任务,最小执行间隔为每天一次
- 专业版——最多40个定时任务,最小执行间隔为每分钟一次
- 最长执行时长——定时触发的函数遵循常规函数的时长限制
Common Patterns
常见模式
- Daily digest: (8:00 AM UTC daily)
"0 8 * * *" - Every hour:
"0 * * * *" - Every 5 minutes (Pro):
"*/5 * * * *" - Weekdays only:
"0 9 * * 1-5"
- 每日摘要:(UTC时间每天上午8点)
"0 8 * * *" - 每小时一次:
"0 * * * *" - 每5分钟一次(专业版):
"*/5 * * * *" - 仅工作日执行:
"0 9 * * 1-5"
Debugging
调试
- Check deployment logs for cron execution results
- Use to watch cron invocations in real time
vercel logs --follow - Cron jobs only run on production deployments, not preview deployments
- 查看部署日志获取定时任务执行结果
- 使用实时监控定时任务调用情况
vercel logs --follow - 定时任务仅在生产环境部署中运行,预览部署不会执行