Skip to content

Commit bb00f9d

Browse files
Fix cron trigger documentation links and inline testing instructions (#11139)
* fix: update cron trigger docs links and inline testing instructions - Updated documentation links to point to the correct cron triggers page - Inlined instructions for testing cron triggers locally in the error message - Users now see the curl command directly in the warning instead of having to click through to docs Co-Authored-By: Steve Faulkner <southpolesteve@gmail.com> * Address PR feedback: remove Miniflare reference from warning message Changed 'Miniflare does not currently trigger scheduled Workers automatically' to 'Scheduled Workers are not automatically triggered during local development' to make the message more user-friendly and avoid referencing internal implementation details. Co-Authored-By: Steve Faulkner <southpolesteve@gmail.com> * Address PR feedback: update endpoint, use logger.once.warn, and improve messaging - Update curl endpoint from /cdn-cgi/mf/scheduled to /cdn-cgi/handler/scheduled - Replace manual didWarnMiniflareCronSupport flag with logger.once.warn() - Remove 'wrangler dev --local' recommendation since warning appears during dev - Make host/port dynamic using config.initialIp and config.initialPort - Handle IPv6 addresses with brackets and 0.0.0.0/:: as localhost - Update template files to use new endpoint and remove --local flag Co-Authored-By: Steve Faulkner <southpolesteve@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
1 parent 8ffbd17 commit bb00f9d

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

.changeset/easy-cars-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Updated cron trigger documentation links and improved error message to include instructions for testing cron triggers locally

packages/wrangler/src/dev/miniflare/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,6 @@ export function buildSitesOptions({
817817
}
818818
}
819819

820-
let didWarnMiniflareCronSupport = false;
821-
822820
export type Options = Extract<MiniflareOptions, { workers: WorkerOptions[] }>;
823821

824822
export async function buildMiniflareOptions(
@@ -829,12 +827,20 @@ export async function buildMiniflareOptions(
829827
onDevRegistryUpdate?: (registry: WorkerRegistry) => void
830828
): Promise<Options> {
831829
if (config.crons?.length && !config.testScheduled) {
832-
if (!didWarnMiniflareCronSupport) {
833-
didWarnMiniflareCronSupport = true;
834-
logger.warn(
835-
"Miniflare does not currently trigger scheduled Workers automatically.\nRefer to https://developers.cloudflare.com/workers/configuration/cron-triggers/#test-cron-triggers for more details "
836-
);
837-
}
830+
const host =
831+
config.initialIp === "0.0.0.0" || config.initialIp === "::"
832+
? "localhost"
833+
: config.initialIp.includes(":")
834+
? `[${config.initialIp}]`
835+
: config.initialIp;
836+
const port = config.initialPort;
837+
838+
logger.once.warn(
839+
`Scheduled Workers are not automatically triggered during local development.\n` +
840+
`To manually trigger a scheduled event, run:\n` +
841+
` curl "http://${host}:${port}/cdn-cgi/handler/scheduled"\n` +
842+
`For more details, see https://developers.cloudflare.com/workers/configuration/cron-triggers/#test-cron-triggers-locally`
843+
);
838844
}
839845

840846
const upstream =

packages/wrangler/templates/new-worker-scheduled.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Welcome to Cloudflare Workers! This is your first scheduled worker.
33
*
4-
* - Run `wrangler dev --local` in your terminal to start a development server
5-
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
4+
* - Run `wrangler dev` in your terminal to start a development server
5+
* - Run `curl "http://localhost:8787/cdn-cgi/handler/scheduled"` to trigger the scheduled event
66
* - Go back to the console to see what your worker has logged
7-
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
7+
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/configuration/cron-triggers/)
88
* - Run `wrangler publish --name my-worker` to publish your worker
99
*
1010
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/

packages/wrangler/templates/new-worker-scheduled.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Welcome to Cloudflare Workers! This is your first scheduled worker.
33
*
4-
* - Run `wrangler dev --local` in your terminal to start a development server
5-
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
4+
* - Run `wrangler dev` in your terminal to start a development server
5+
* - Run `curl "http://localhost:8787/cdn-cgi/handler/scheduled"` to trigger the scheduled event
66
* - Go back to the console to see what your worker has logged
7-
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
7+
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/configuration/cron-triggers/)
88
* - Run `wrangler deploy --name my-worker` to deploy your worker
99
*
1010
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/

0 commit comments

Comments
 (0)