Newshot
Account

Vercel Schedules 进入公开测试,支持定时与按需运行任务

AI summary

Vercel Schedules 现已在所有套餐开放公开测试,可按周期或单次时间点在生产、预览或自定义环境中运行任务。调度目标可以是私有 Vercel Function、HTTP 路径或 Vercel Queue 主题,且无需重新部署即可启用、禁用或按需运行。它是 Cron Jobs 的继任者,现有 Cron Jobs 继续可用。

Translation(model translation, not the source's own text)

Vercel Schedules 现已进入公测

题图
题图

Vercel Schedules 现已在所有套餐中进入公测。可以在生产、预览或自定义环境中,按循环节奏或在单个时间点运行任务。

vercel.json 中的调度可以指向私有 Vercel Function、HTTP 路径或 Vercel Queue 主题,而运行时创建的调度则指向一个 Queue 主题。任何调度都可以启用、停用或按需运行,无需重新部署。

定义一个静态调度:


        {   "schedules": {     "cleanup": {       "schedule": "0 * * * *",       "function": "api/cleanup.ts",       "timezone": "America/New_York"     }   },   "functions": {     "api/cleanup.ts": {       "experimentalTriggers": [{ "type": "schedule/v1beta" }]     }   } }
      

vercel.json 中一个按小时运行的静态调度,目标是私有 Vercel Function

添加 schedule/v1beta 触发器会使该函数变为私有。它没有公共 URL,且只有 Vercel 调度基础设施能调用它。

处理派发:


        import { handleSchedule } from '@vercel/schedules';
export const POST = handleSchedule(async (metadata) => {  console.log(`Running ${metadata.name} at ${metadata.scheduledAt}`);  await deleteExpiredRecords(); });
      

使用 @vercel/schedules 中的 handleSchedule 处理调度派发

在运行时创建调度:


        import { Schedules } from '@vercel/schedules';
await Schedules.create({  name: 'daily-digest',  target: { topic: 'digests' },  expression: { type: 'cron', cron: '0 9 * * *' },  timezone: 'America/Los_Angeles',  payload: { reportType: 'summary' },});
      

在运行时创建一个会派发到 Queue 主题的调度

Schedules 是 Cron Jobs 的后继者。现有的 Cron Jobs 继续可用,迁移指南介绍了如何将它们迁移到 Schedules。Schedules 还为 Eve 中的动态调度以及 Nitro 项目中的实验性定时任务提供支持。

Vercel Schedules 在 Pro 和 Enterprise 上的计费起价为每 100 万次运行 $5、每 100 万次创建 $10。Hobby 每月包含 500 次调度创建和 5,000 次运行。阅读博客文章,进一步了解 Schedules 的工作方式,然后从 Schedules 文档开始使用。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Vercel Blog
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗