智能体
developers.cloudflare.com ·
@Cloudflare Developers
Cloudflare Workers 本地开发支持测试 Cron Triggers
Cloudflare 更新 Local Explorer,开发者可在本地开发时向 Worker 的 scheduled() handler 发送一次性 Cron Trigger 调用,无需构造请求 URL。通过 cf dev、wrangler dev 或 Vite 插件启动服务后,访问 /cdn-cgi/local/explorer 即可调用已配置的 cron 表达式、构建临时表达式、设置可复用调度时间并查看结果与 noRetry() 状态。临时触发和预设仅保存在浏览器,不修改配置文件或已部署的 Cron Triggers,本地开发也不会自动运行 cron 调度。Local Explorer API 提供相同操作,可供工具和 AI Agent 调用。
AI推荐理由 Cloudflare 官方 changelog 明确说明 Local Explorer 新增本地触发 Cron Trigger 的能力,可直接调用 Worker 的 scheduled() handler,并支持浏览器界面与 API 两种方式;API 面向工具和 AI Agent,属于可验证的开发工具改进。局限在于仅限本地开发、不会自动运行 cron 调度,且未提供实际使用效果或性能数据。
72
正文
Local Explorer can now send one-off Cron Trigger invocations to a Worker's `scheduled()` handler during local development. This removes the need to construct request URLs when testing handler behavior.
Start your local development server with [`cf dev`](https://developers.cloudflare.com/cf/projects/#start-development), [`wrangler dev`](https://developers.cloudflare.com/workers/wrangler/commands/general/#dev), or the [Cloudflare Vite plugin](https://developers.cloudflare.com/workers/vite-plugin/). Open `/cdn-cgi/local/explorer` on the server URL and select **Cron Triggers**.
The browser interface supports the following tasks:
* Invoke configured cron expressions
* Build ad hoc expressions
* Set reusable scheduled times
* Inspect outcomes and `noRetry()` status
Ad hoc triggers and scheduled time presets stay in your browser. They do not change `cloudflare.config.ts`, your Wrangler configuration, or deployed Cron Triggers. Local development does not run cron schedules automatically.
Full logs and traces are available in the development session that owns the Worker when that session has **Observability** turned on.
The following example uses port `8787`. Replace it with your development server port, such as `5173` for Vite.
The Local Explorer API exposes the same operation for tools and AI agents. The request targets an exact Worker name and accepts a cron expression and optional scheduled time:
```
curl -X POST \
"http://localhost:8787/cdn-cgi/local/explorer/api/local/scheduled?worker=my-worker" \
-H "Content-Type: application/json" \
--data '{"cron":"0 * * * *","scheduled_time":1745856238000}'
```
For more details, refer to [Test Cron Triggers with Local Explorer](https://developers.cloudflare.com/workers/local-development/local-explorer/#test-cron-triggers).