Skip to content

Commit 142dd60

Browse files
committed
Add attemptDeadlineSeconds support to v2 scheduled functions
1 parent 53747e5 commit 142dd60

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
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: 6 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,
@@ -54,6 +55,7 @@ describe("schedule", () => {
5455
const options: schedule.ScheduleOptions = {
5556
schedule: "* * * * *",
5657
timeZone: "utc",
58+
attemptDeadlineSeconds: 300,
5759
retryCount: 3,
5860
maxRetrySeconds: 1,
5961
minBackoffSeconds: 2,
@@ -66,6 +68,7 @@ describe("schedule", () => {
6668
expect(schedule.getOpts(options)).to.deep.eq({
6769
schedule: "* * * * *",
6870
timeZone: "utc",
71+
attemptDeadlineSeconds: 300,
6972
retryConfig: {
7073
retryCount: 3,
7174
maxRetrySeconds: 1,
@@ -108,6 +111,7 @@ describe("schedule", () => {
108111
{
109112
schedule: "* * * * *",
110113
timeZone: "utc",
114+
attemptDeadlineSeconds: 600,
111115
retryCount: 3,
112116
maxRetrySeconds: 10,
113117
minBackoffSeconds: 11,
@@ -127,6 +131,7 @@ describe("schedule", () => {
127131
scheduleTrigger: {
128132
schedule: "* * * * *",
129133
timeZone: "utc",
134+
attemptDeadlineSeconds: 600,
130135
retryConfig: {
131136
retryCount: 3,
132137
maxRetrySeconds: 10,
@@ -159,6 +164,7 @@ describe("schedule", () => {
159164
scheduleTrigger: {
160165
schedule: "* * * * *",
161166
timeZone: undefined,
167+
attemptDeadlineSeconds: undefined,
162168
retryConfig: {
163169
retryCount: undefined,
164170
maxRetrySeconds: undefined,

src/runtime/manifest.ts

Lines changed: 7 additions & 1 deletion
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;
@@ -302,5 +303,10 @@ export function initV2ScheduleTrigger(
302303
schedule: string | Expression<string>,
303304
...opts: ManifestOptions[]
304305
): ManifestEndpoint["scheduleTrigger"] {
305-
return initScheduleTrigger(RESETTABLE_V2_SCHEDULE_OPTIONS, schedule, ...opts);
306+
const trigger = initScheduleTrigger(RESETTABLE_V2_SCHEDULE_OPTIONS, schedule, ...opts);
307+
// Set attemptDeadlineSeconds for v2 only
308+
if (trigger.timeZone === RESET_VALUE) {
309+
trigger.attemptDeadlineSeconds = RESET_VALUE;
310+
}
311+
return trigger;
306312
}

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 attempting the job in 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)