跳到正文
Vercel Blog(vercel.com)· Elliot Dauber·· 6 小時前品質評分63

Vercel Schedules 進入公開測試版,支援所有方案的定時任務設定

Vercel Schedules is now in public beta

重點導讀

Vercel Schedules 現已進入公開測試版,允許在所有方案中以 cron 語法設定定時或單次任務,並可在生產、預覽或自訂環境執行。

  • 功能範圍:可針對私有 Vercel Function、HTTP 路徑或 Vercel Queue 主題設定排程,執行時可啟用、停用或即時觸發,無需重新部署。

AI 伴隨問答

自備 Key 深度分析

針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:

正文

Vercel Schedules is now in public beta on all plans. Run tasks on a recurring cadence or at a single point in time, in production, preview, or custom environments.

Schedules in vercel.json can target a private Vercel Function, an HTTP path, or a Vercel Queue topic, and schedules created at runtime target a Queue topic. Any schedule can be enabled, disabled, or run on demand without redeploying.

Define a static schedule:

vercel.json

{

"schedules": {

"cleanup": {

"schedule": "0 * * * *",

"function": "api/cleanup.ts",

"timezone": "America/New_York"

}

},

"functions": {

"api/cleanup.ts": {

"experimentalTriggers": [{ "type": "schedule/v1beta" }]

}

}

}

An hourly static schedule in vercel.json, targeting a private Vercel Function

Adding a schedule/v1beta trigger makes the function private. It has no public URL and only the Vercel schedule infrastructure can invoke it.

Handle the dispatch:

api/cleanup.ts

import { handleSchedule } from '@vercel/schedules';

export const POST = handleSchedule(async (metadata) => {

console.log(`Running ${metadata.name} at ${metadata.scheduledAt}`);

await deleteExpiredRecords();

});

Handling the schedule dispatch with handleSchedule from @vercel/schedules

Create a schedule at runtime:

lib/schedules.ts

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' },

});

Creating a schedule at runtime that dispatches to a Queue topic

Schedules is the successor to Cron Jobs. Existing Cron Jobs continue to work, and the migration guide covers moving them to Schedules. Schedules also power dynamic schedules in Eve and experimental scheduled tasks in Nitro projects.

Vercel Schedules is billed starting at $5 per 1M runs and $10 per 1M creations on Pro and Enterprise. Hobby includes 500 schedule creations and 5,000 runs per month. Read the blog post for more on how Schedules works, then get started with the Schedules documentation.

來源: Vercel Blog (vercel.com)
開啟原文

讀者討論

理性交流 · 即時討論