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

Vercel Schedules 介紹

Introducing Vercel Schedules

重點導讀

Vercel Schedules 允許開發者在應用執行時即時建立、修改或取消單次與重複排程,無需重新部署。

  • 靜態排程:在 vercel.json 或 Build Output API 中設定,部署時同步。

AI 伴隨問答

自備 Key 深度分析

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

正文

Cron jobs are useful for work that needs to happen regularly. You can use them to do things such as back up your database on a schedule, or keep data in sync between two systems.

You define them once in code and then can update them by editing their config and redeploying. But today, agents interact with users as work evolves, and schedules need to be updated in real time.

We built Vercel Schedules to allow agents and applications to create, change, or cancel one-time and recurring schedules through code, without redeploying.

What are Vercel Schedules?

Schedules builds on the static approach used by Vercel Cron Jobs, but are designed to let users and agents decide when work should happen while your application is still running. A schedule tells Vercel when to trigger a task and where to send it. Your application provides the code that carries out the work.

You can use schedules for both static and dynamic jobs:

  • Static schedules keep the timing in vercel.json or Build Output API configuration and sync when you deploy. You can use them to call private functions or HTTP paths, or send messages to Queue topics.

  • Dynamic schedules let your app create and manage schedules through the JS SDK, CLI, or API as it runs. They support one-time and recurring work through Queue topics.

You can also test scheduled work on Preview deployments and in custom environments before running it in Production.

How Schedules works

Take this example: A user could ask an agent with web access, “Tomorrow morning, summarize the top five stories on Hacker News.” The traditional solution would be storing the request and its schedule time in a database, then using a cron job to check for work that is due.

With Schedules, an agent can create a schedule that records the request and when to run it, without a separate database and polling job. The example below defines an AI SDK tool that gives an agent this capability.

When the task is due, Vercel uses Queues to deliver the saved request to your app. Your app provides code to read that request, check the user’s current permissions, and start the agent. The agent fetches the top five Hacker News posts with a web tool, then returns a summary for your app to save for the user.

If you already build agents with fx’s JavaScript library, libfx or Pi’s agent library, you can add a similar scheduling tool. The eve agent framework uses Vercel Schedules to provide dynamic scheduling tools for production agents hosted on Vercel.

Run recurring application jobs

You can schedule recurring work with Vercel Schedules. Schedules can be created dynamically via the JS SDK, API, and CLI, or set up in your project’s configuration.

For example, to create a job that cleans up expired records every day, you could define a schedule that invokes a private function in your chosen time zone:

Vercel calls this cleanup code directly, without exposing it at a public URL. It checks that each call comes from the scheduling service, so you don’t have to add that check yourself.

If your app already uses the Nitro 3 server framework, its experimental integration lets you run the recurring jobs in your existing scheduledTasks configuration as private functions.

You can also try the agent task and cleanup locally with vercel dev, then test them on a Preview branch or in a custom environment before production. Use Run Schedule in your project’s Schedules tab to try either task without waiting, and see when past runs happened.

Get started

Vercel Schedules is now in Public Beta, and you can use it for the recurring tasks your application already runs. When a user or agent chooses when work should happen, your code can create and manage a schedule for that task.

To get started, check out the Vercel Schedules skill and read the documentation.

Read more

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

讀者討論

理性交流 · 即時討論