Skip to content

Commit 5cecb79

Browse files
petebacondarwinAnka
authored andcommitted
fix: setting triggers.crons:[] in Wrangler config should delete deployed cron schedules
1 parent 642e8d3 commit 5cecb79

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

.changeset/shaky-planets-feel.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+
fix: setting triggers.crons:[] in Wrangler config should delete deployed cron schedules

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe("normalizeAndValidateConfig()", () => {
114114
ai: undefined,
115115
version_metadata: undefined,
116116
triggers: {
117-
crons: [],
117+
crons: undefined,
118118
},
119119
unsafe: {
120120
bindings: undefined,

packages/wrangler/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export const defaultWranglerConfig: Config = {
371371
jsx_fragment: "React.Fragment",
372372
migrations: [],
373373
triggers: {
374-
crons: [],
374+
crons: undefined,
375375
},
376376
usage_model: undefined,
377377
rules: [],

packages/wrangler/src/config/environment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ interface EnvironmentInheritable {
248248
*
249249
* More details here https://developers.cloudflare.com/workers/platform/cron-triggers
250250
*
251-
* @default {crons:[]}
251+
* @default {crons: undefined}
252252
* @inheritable
253253
*/
254-
triggers: { crons: string[] };
254+
triggers: { crons: string[] | undefined };
255255

256256
/**
257257
* Specifies the Usage Model for your Worker. There are two options -

packages/wrangler/src/config/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ function normalizeAndValidateEnvironment(
13381338
rawEnv,
13391339
"triggers",
13401340
isObjectWith("crons"),
1341-
{ crons: [] }
1341+
{ crons: undefined }
13421342
),
13431343
assets: normalizeAndValidateAssets(diagnostics, topLevelEnv, rawEnv),
13441344
usage_model: inheritable(

packages/wrangler/src/dev/miniflare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ export async function buildMiniflareOptions(
957957
internalObjects: CfDurableObject[];
958958
entrypointNames: string[];
959959
}> {
960-
if (config.crons.length > 0 && !config.testScheduled) {
960+
if (config.crons?.length && !config.testScheduled) {
961961
if (!didWarnMiniflareCronSupport) {
962962
didWarnMiniflareCronSupport = true;
963963
log.warn(

packages/wrangler/src/triggers/deploy.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default async function triggersDeploy(
3838
): Promise<string[] | void> {
3939
const { config, accountId, name: scriptName } = props;
4040

41-
const triggers = props.triggers || config.triggers?.crons;
41+
const schedules = props.triggers || config.triggers?.crons;
4242
const routes =
4343
props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? [];
4444
const routesOnly: Array<Route> = [];
@@ -258,17 +258,18 @@ export default async function triggersDeploy(
258258
}
259259

260260
// Configure any schedules for the script.
261-
// TODO: rename this to `schedules`?
262-
if (triggers && triggers.length) {
261+
// If schedules is not defined then we just leave whatever is previously deployed alone.
262+
// If it is an empty array we will remove all schedules.
263+
if (schedules) {
263264
deployments.push(
264265
fetchResult(`${workerUrl}/schedules`, {
265266
// Note: PUT will override previous schedules on this script.
266267
method: "PUT",
267-
body: JSON.stringify(triggers.map((cron) => ({ cron }))),
268+
body: JSON.stringify(schedules.map((cron) => ({ cron }))),
268269
headers: {
269270
"Content-Type": "application/json",
270271
},
271-
}).then(() => triggers.map((trigger) => `schedule: ${trigger}`))
272+
}).then(() => schedules.map((trigger) => `schedule: ${trigger}`))
272273
);
273274
}
274275

0 commit comments

Comments
 (0)