Skip to content

Commit 33f9cad

Browse files
committed
feat(scheduler): add support for attemptDeadline in onSchedule
1 parent 5e2c5f8 commit 33f9cad

File tree

9 files changed

+68
-13
lines changed

9 files changed

+68
-13
lines changed

spec/runtime/manifest.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ describe("initScheduleTrigger", () => {
265265
maxRetryDuration: RESET_VALUE,
266266
minBackoffDuration: RESET_VALUE,
267267
maxBackoffDuration: RESET_VALUE,
268+
attemptDeadline: RESET_VALUE,
268269
},
269270
});
270271
});
@@ -292,6 +293,7 @@ describe("initScheduleTrigger", () => {
292293
maxRetrySeconds: RESET_VALUE,
293294
minBackoffSeconds: RESET_VALUE,
294295
maxBackoffSeconds: RESET_VALUE,
296+
attemptDeadline: RESET_VALUE,
295297
},
296298
});
297299
});

spec/v1/cloud-functions.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ describe("makeCloudFunction", () => {
212212
maxDoublings: RESET_VALUE,
213213
maxRetryDuration: RESET_VALUE,
214214
minBackoffDuration: RESET_VALUE,
215+
attemptDeadline: RESET_VALUE,
215216
},
216217
},
217218
labels: {},

spec/v1/providers/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ export const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = {
4646
maxBackoffDuration: options.RESET_VALUE,
4747
minBackoffDuration: options.RESET_VALUE,
4848
maxDoublings: options.RESET_VALUE,
49+
attemptDeadline: options.RESET_VALUE,
4950
},
5051
};

spec/v1/providers/pubsub.spec.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ describe("Pubsub Functions", () => {
215215
expect(result.__endpoint.scheduleTrigger).to.deep.equal({
216216
...MINIMAL_SCHEDULE_TRIGGER,
217217
schedule: "every 5 minutes",
218-
retryConfig,
218+
retryConfig: {
219+
...retryConfig,
220+
attemptDeadline: RESET_VALUE,
221+
},
219222
});
220223
expect(result.__endpoint.labels).to.be.empty;
221224
});
@@ -249,7 +252,10 @@ describe("Pubsub Functions", () => {
249252
expect(result.__endpoint.scheduleTrigger).to.deep.equal({
250253
...MINIMAL_SCHEDULE_TRIGGER,
251254
schedule: "every 5 minutes",
252-
retryConfig,
255+
retryConfig: {
256+
...retryConfig,
257+
attemptDeadline: RESET_VALUE,
258+
},
253259
timeZone: "America/New_York",
254260
});
255261
expect(result.__endpoint.labels).to.be.empty;
@@ -341,7 +347,10 @@ describe("Pubsub Functions", () => {
341347
...MINIMAL_SCHEDULE_TRIGGER,
342348
schedule: "every 5 minutes",
343349
timeZone: RESET_VALUE,
344-
retryConfig,
350+
retryConfig: {
351+
...retryConfig,
352+
attemptDeadline: RESET_VALUE,
353+
},
345354
});
346355
expect(result.__endpoint.region).to.deep.equal(["us-east1"]);
347356
expect(result.__endpoint.availableMemoryMb).to.deep.equal(256);
@@ -382,7 +391,10 @@ describe("Pubsub Functions", () => {
382391
...MINIMAL_SCHEDULE_TRIGGER,
383392
schedule: "every 5 minutes",
384393
timeZone: "America/New_York",
385-
retryConfig,
394+
retryConfig: {
395+
...retryConfig,
396+
attemptDeadline: RESET_VALUE,
397+
},
386398
});
387399
expect(result.__endpoint.region).to.deep.equal(["us-east1"]);
388400
expect(result.__endpoint.availableMemoryMb).to.deep.equal(256);

spec/v2/providers/scheduler.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = {
3838
minBackoffSeconds: options.RESET_VALUE,
3939
maxBackoffSeconds: options.RESET_VALUE,
4040
maxDoublings: options.RESET_VALUE,
41+
attemptDeadline: options.RESET_VALUE,
4142
},
4243
};
4344

@@ -103,6 +104,20 @@ describe("schedule", () => {
103104
]);
104105
});
105106

107+
it("should create a schedule function with attemptDeadline", () => {
108+
const schfn = schedule.onSchedule(
109+
{
110+
schedule: "* * * * *",
111+
attemptDeadline: "320s",
112+
},
113+
() => undefined
114+
);
115+
116+
expect(schfn.__endpoint.scheduleTrigger?.retryConfig?.attemptDeadline).to.equal(
117+
"320s"
118+
);
119+
});
120+
106121
it("should create a schedule function given options", () => {
107122
const schfn = schedule.onSchedule(
108123
{
@@ -133,6 +148,7 @@ describe("schedule", () => {
133148
minBackoffSeconds: 11,
134149
maxBackoffSeconds: 12,
135150
maxDoublings: 2,
151+
attemptDeadline: options.RESET_VALUE,
136152
},
137153
},
138154
});

src/runtime/manifest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface ManifestEndpoint {
107107
maxRetryDuration?: string | Expression<string> | ResetValue;
108108
minBackoffDuration?: string | Expression<string> | ResetValue;
109109
maxBackoffDuration?: string | Expression<string> | ResetValue;
110+
attemptDeadline?: string | Expression<string> | ResetValue;
110111
};
111112
};
112113

@@ -254,6 +255,7 @@ const RESETTABLE_V1_SCHEDULE_OPTIONS: Omit<
254255
maxRetryDuration: null,
255256
maxBackoffDuration: null,
256257
minBackoffDuration: null,
258+
attemptDeadline: null,
257259
};
258260

259261
const RESETTABLE_V2_SCHEDULE_OPTIONS: Omit<
@@ -265,6 +267,7 @@ const RESETTABLE_V2_SCHEDULE_OPTIONS: Omit<
265267
maxRetrySeconds: null,
266268
minBackoffSeconds: null,
267269
maxBackoffSeconds: null,
270+
attemptDeadline: null,
268271
};
269272

270273
function initScheduleTrigger(

src/v1/cloud-functions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ export function makeCloudFunction<EventData>({
485485
"maxDoublings",
486486
"maxBackoffDuration",
487487
"maxRetryDuration",
488-
"minBackoffDuration"
488+
"minBackoffDuration",
489+
"attemptDeadline"
489490
);
490491
} else {
491492
endpoint.eventTrigger = {

src/v1/function-configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export interface ScheduleRetryConfig {
110110
* @defaultValue 5
111111
*/
112112
maxDoublings?: number | Expression<number> | ResetValue;
113+
114+
/**
115+
* The deadline for each job attempt, specified as a duration string (e.g. "600s").
116+
*/
117+
attemptDeadline?: string | Expression<string> | ResetValue;
113118
}
114119

115120
/**

src/v2/providers/scheduler.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface SeparatedOpts {
4848
minBackoffSeconds?: number | Expression<number> | ResetValue;
4949
maxBackoffSeconds?: number | Expression<number> | ResetValue;
5050
maxDoublings?: number | Expression<number> | ResetValue;
51+
attemptDeadline?: string | Expression<string> | ResetValue;
5152
};
5253
opts: options.GlobalOptions;
5354
}
@@ -60,16 +61,22 @@ export function getOpts(args: string | ScheduleOptions): SeparatedOpts {
6061
opts: {} as options.GlobalOptions,
6162
};
6263
}
64+
const retryConfig: any = {
65+
retryCount: args.retryCount,
66+
maxRetrySeconds: args.maxRetrySeconds,
67+
minBackoffSeconds: args.minBackoffSeconds,
68+
maxBackoffSeconds: args.maxBackoffSeconds,
69+
maxDoublings: args.maxDoublings,
70+
};
71+
72+
if (args.attemptDeadline !== undefined) {
73+
retryConfig.attemptDeadline = args.attemptDeadline;
74+
}
75+
6376
return {
6477
schedule: args.schedule,
6578
timeZone: args.timeZone,
66-
retryConfig: {
67-
retryCount: args.retryCount,
68-
maxRetrySeconds: args.maxRetrySeconds,
69-
minBackoffSeconds: args.minBackoffSeconds,
70-
maxBackoffSeconds: args.maxBackoffSeconds,
71-
maxDoublings: args.maxDoublings,
72-
},
79+
retryConfig,
7380
opts: args as options.GlobalOptions,
7481
};
7582
}
@@ -125,6 +132,12 @@ export interface ScheduleOptions extends options.GlobalOptions {
125132

126133
/** The time between will double max doublings times. */
127134
maxDoublings?: number | Expression<number> | ResetValue;
135+
136+
/**
137+
* The deadline for each job attempt, specified as a duration string (e.g. "600s").
138+
* See: https://cloud.google.com/scheduler/docs/reference/rest/v1/projects.locations.jobs#Job
139+
*/
140+
attemptDeadline?: string | Expression<string> | ResetValue;
128141
}
129142

130143
/**
@@ -204,7 +217,8 @@ export function onSchedule(
204217
"maxRetrySeconds",
205218
"minBackoffSeconds",
206219
"maxBackoffSeconds",
207-
"maxDoublings"
220+
"maxDoublings",
221+
"attemptDeadline"
208222
);
209223
func.__endpoint = ep;
210224

0 commit comments

Comments
 (0)