cloudflare / cloudflare/workers-sdk

triggers.crons silently dropped when deploying with --dispatch-namespace (Workers for Platforms)

Open
#13,840 1 comment 1 reaction 1 assignee Claimed by @dinasaur404 View on GitHub
api package:wrangler product:workers-for-platforms
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

Hi team,

I wanted to flag a behavior that surprised me, and ask whether it's intentional, planned to change, or just undocumented.

## What I'm seeing

I'm building a SaaS that hosts customer Next.js sites on Workers for Platforms. Each tenant site is uploaded to a dispatch namespace. When a customer project includes `triggers.crons` in `wrangler.jsonc`, the deploy succeeds and the site works, but the cron never fires. There is no warning, no error, and nothing in the deploy output that signals the schedule was dropped. I spent a non-trivial amount of time chasing this before I realised the crons were just being thrown away.

## Where it happens in the source

In `packages/wrangler/src/deploy/deploy.ts` around line 1292 there is an early return when `dispatchNamespace` is set, before `triggersDeploy()` would run:

```ts
// Early exit for WfP since it doesn't need the below code
if (props.dispatchNamespace !== undefined) {
deployWfpUserWorker(props.dispatchNamespace, versionId);
return { versionId, workerTag };
}
```

`packages/wrangler/src/triggers/deploy.ts:44` is the only place that reads `config.triggers.crons` for deployment, and the only place that calls the `/schedules` API. Since the dispatch namespace path returns early, that file never runs and nothing is sent to Cloudflare.

I also looked on the API side. The dispatch namespace scripts resource at `/accounts/{id}/workers/dispatch/namespaces/{ns}/scripts/{name}` does not appear to have a `/schedules` subresource. The schedules API only exists for account-scoped scripts at `/accounts/{id}/workers/scripts/{name}/schedules`.

## What I'd love to know

1. Is cron support for dispatch namespace user workers something that's planned, on the roadmap, or considered out of scope? I noticed Workflows are explicitly listed as not supported in Workers for Platforms, so I wanted to ask whether crons are in the same bucket.

2. If it isn't planned, would the team be open to adding a wrangler warning when `triggers.crons` is set alongside `--dispatch-namespace`? We can build around a missing feature, but the silent dropping was the painful part.

3. Is there a pattern Cloudflare recommends for platforms that want to offer scheduled tasks to tenant workers? I've found the "platform-owned cron worker that fans out through the dispatcher" pattern in community posts and that's what we'll likely build, but I wasn't sure whether there's something more official.

Happy to provide more context. Thanks for reading.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.