Skip to content

Commit 4ca804b

Browse files
committed
feat: add attemptDeadlineSeconds support to v2 scheduled functions
Adds attemptDeadlineSeconds to ScheduleOptions and ManifestEndpoint. Updates onSchedule to pass attemptDeadlineSeconds to the manifest. Adds tests for attemptDeadlineSeconds.
1 parent 53747e5 commit 4ca804b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

spec/runtime/manifest.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ describe("initScheduleTrigger", () => {
286286
expect(st).to.deep.eq({
287287
schedule: "every 30 minutes",
288288
timeZone: RESET_VALUE,
289+
attemptDeadlineSeconds: RESET_VALUE,
289290
retryConfig: {
290291
retryCount: RESET_VALUE,
291292
maxDoublings: RESET_VALUE,

spec/v2/providers/scheduler.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { runHandler } from "../../helper";
3232
const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = {
3333
schedule: "",
3434
timeZone: options.RESET_VALUE,
35+
attemptDeadlineSeconds: options.RESET_VALUE,
3536
retryConfig: {
3637
retryCount: options.RESET_VALUE,
3738
maxRetrySeconds: options.RESET_VALUE,
@@ -66,6 +67,7 @@ describe("schedule", () => {
6667
expect(schedule.getOpts(options)).to.deep.eq({
6768
schedule: "* * * * *",
6869
timeZone: "utc",
70+
attemptDeadlineSeconds: undefined,
6971
retryConfig: {
7072
retryCount: 3,
7173
maxRetrySeconds: 1,
@@ -108,6 +110,7 @@ describe("schedule", () => {
108110
{
109111
schedule: "* * * * *",
110112
timeZone: "utc",
113+
attemptDeadlineSeconds: 300,
111114
retryCount: 3,
112115
maxRetrySeconds: 10,
113116
minBackoffSeconds: 11,
@@ -127,6 +130,7 @@ describe("schedule", () => {
127130
scheduleTrigger: {
128131
schedule: "* * * * *",
129132
timeZone: "utc",
133+
attemptDeadlineSeconds: 300,
130134
retryConfig: {
131135
retryCount: 3,
132136
maxRetrySeconds: 10,
@@ -159,6 +163,7 @@ describe("schedule", () => {
159163
scheduleTrigger: {
160164
schedule: "* * * * *",
161165
timeZone: undefined,
166+
attemptDeadlineSeconds: undefined,
162167
retryConfig: {
163168
retryCount: undefined,
164169
maxRetrySeconds: undefined,

src/runtime/manifest.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export interface ManifestEndpoint {
9797
scheduleTrigger?: {
9898
schedule: string | Expression<string>;
9999
timeZone?: string | Expression<string> | ResetValue;
100+
attemptDeadlineSeconds?: number | Expression<number> | ResetValue;
100101
retryConfig?: {
101102
retryCount?: number | Expression<number> | ResetValue;
102103
maxRetrySeconds?: string | Expression<string> | ResetValue;
@@ -259,12 +260,14 @@ const RESETTABLE_V1_SCHEDULE_OPTIONS: Omit<
259260
const RESETTABLE_V2_SCHEDULE_OPTIONS: Omit<
260261
ResettableKeys<ManifestEndpoint["scheduleTrigger"]["retryConfig"]>,
261262
"maxRetryDuration" | "maxBackoffDuration" | "minBackoffDuration"
262-
> = {
263+
> &
264+
Pick<ResettableKeys<ManifestEndpoint["scheduleTrigger"]>, "attemptDeadlineSeconds"> = {
263265
retryCount: null,
264266
maxDoublings: null,
265267
maxRetrySeconds: null,
266268
minBackoffSeconds: null,
267269
maxBackoffSeconds: null,
270+
attemptDeadlineSeconds: null,
268271
};
269272

270273
function initScheduleTrigger(
@@ -278,7 +281,11 @@ function initScheduleTrigger(
278281
};
279282
if (opts.every((opt) => !opt?.preserveExternalChanges)) {
280283
for (const key of Object.keys(resetOptions)) {
281-
scheduleTrigger.retryConfig[key] = RESET_VALUE;
284+
if (key === "attemptDeadlineSeconds") {
285+
scheduleTrigger[key] = RESET_VALUE;
286+
} else {
287+
scheduleTrigger.retryConfig[key] = RESET_VALUE;
288+
}
282289
}
283290
scheduleTrigger = { ...scheduleTrigger, timeZone: RESET_VALUE };
284291
}

src/v2/providers/scheduler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { withInit } from "../../common/onInit";
4242
interface SeparatedOpts {
4343
schedule: string | Expression<string>;
4444
timeZone?: timezone | Expression<string> | ResetValue;
45+
attemptDeadlineSeconds?: number | Expression<number> | ResetValue;
4546
retryConfig?: {
4647
retryCount?: number | Expression<number> | ResetValue;
4748
maxRetrySeconds?: number | Expression<number> | ResetValue;
@@ -63,6 +64,7 @@ export function getOpts(args: string | ScheduleOptions): SeparatedOpts {
6364
return {
6465
schedule: args.schedule,
6566
timeZone: args.timeZone,
67+
attemptDeadlineSeconds: args.attemptDeadlineSeconds,
6668
retryConfig: {
6769
retryCount: args.retryCount,
6870
maxRetrySeconds: args.maxRetrySeconds,
@@ -111,6 +113,9 @@ export interface ScheduleOptions extends options.GlobalOptions {
111113
/** The timezone that the schedule executes in. */
112114
timeZone?: timezone | Expression<string> | ResetValue;
113115

116+
/** The deadline for job attempts. Defaults to 180 seconds. */
117+
attemptDeadlineSeconds?: number | Expression<number> | ResetValue;
118+
114119
/** The number of retry attempts for a failed run. */
115120
retryCount?: number | Expression<number> | ResetValue;
116121

@@ -196,7 +201,7 @@ export function onSchedule(
196201
scheduleTrigger: initV2ScheduleTrigger(separatedOpts.schedule, globalOpts, separatedOpts.opts),
197202
};
198203

199-
copyIfPresent(ep.scheduleTrigger, separatedOpts, "timeZone");
204+
copyIfPresent(ep.scheduleTrigger, separatedOpts, "timeZone", "attemptDeadlineSeconds");
200205
copyIfPresent(
201206
ep.scheduleTrigger.retryConfig,
202207
separatedOpts.retryConfig,

0 commit comments

Comments
 (0)