Skip to content

Commit 01dd6d5

Browse files
committed
feat: tie scheduled function attemptDeadline to timeoutSeconds
1 parent 2c2c78d commit 01dd6d5

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

spec/v2/providers/scheduler.spec.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { MINIMAL_V2_ENDPOINT } from "../../fixtures";
2828
import { onInit } from "../../../src/v2/core";
2929
import { MockRequest } from "../../fixtures/mockrequest";
3030
import { runHandler } from "../../helper";
31+
import * as params from "../../../src/params";
3132

3233
const MINIMAL_SCHEDULE_TRIGGER: ManifestEndpoint["scheduleTrigger"] = {
3334
schedule: "",
@@ -67,7 +68,6 @@ describe("schedule", () => {
6768
expect(schedule.getOpts(options)).to.deep.eq({
6869
schedule: "* * * * *",
6970
timeZone: "utc",
70-
attemptDeadlineSeconds: undefined,
7171
retryConfig: {
7272
retryCount: 3,
7373
maxRetrySeconds: 1,
@@ -110,7 +110,7 @@ describe("schedule", () => {
110110
{
111111
schedule: "* * * * *",
112112
timeZone: "utc",
113-
attemptDeadlineSeconds: 300,
113+
timeoutSeconds: 300,
114114
retryCount: 3,
115115
maxRetrySeconds: 10,
116116
minBackoffSeconds: 11,
@@ -127,6 +127,7 @@ describe("schedule", () => {
127127
platform: "gcfv2",
128128
labels: { key: "val" },
129129
region: ["us-central1"],
130+
timeoutSeconds: 300,
130131
scheduleTrigger: {
131132
schedule: "* * * * *",
132133
timeZone: "utc",
@@ -157,13 +158,12 @@ describe("schedule", () => {
157158
() => console.log(1)
158159
);
159160

160-
expect(schfn.__endpoint).to.deep.eq({
161+
expect(schfn.__endpoint).to.deep.equal({
161162
platform: "gcfv2",
162163
labels: {},
163164
scheduleTrigger: {
164165
schedule: "* * * * *",
165166
timeZone: undefined,
166-
attemptDeadlineSeconds: undefined,
167167
retryConfig: {
168168
retryCount: undefined,
169169
maxRetrySeconds: undefined,
@@ -181,6 +181,33 @@ describe("schedule", () => {
181181
]);
182182
});
183183

184+
it("should set attemptDeadlineSeconds from timeoutSeconds", () => {
185+
const schfn = schedule.onSchedule(
186+
{
187+
schedule: "* * * * *",
188+
timeoutSeconds: 3600,
189+
},
190+
() => undefined
191+
);
192+
193+
expect(schfn.__endpoint.timeoutSeconds).to.deep.eq(3600);
194+
expect(schfn.__endpoint.scheduleTrigger?.attemptDeadlineSeconds).to.deep.eq(3600);
195+
});
196+
197+
it("should set attemptDeadlineSeconds from Expression timeoutSeconds", () => {
198+
const timeout = params.defineInt("TIMEOUT");
199+
const schfn = schedule.onSchedule(
200+
{
201+
schedule: "* * * * *",
202+
timeoutSeconds: timeout,
203+
},
204+
() => undefined
205+
);
206+
207+
expect(schfn.__endpoint.timeoutSeconds).to.deep.eq(timeout);
208+
expect(schfn.__endpoint.scheduleTrigger?.attemptDeadlineSeconds).to.deep.eq(timeout);
209+
});
210+
184211
it("should have a .run method", async () => {
185212
const testObj = {
186213
foo: "bar",

src/v2/providers/scheduler.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ 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;
4645
retryConfig?: {
4746
retryCount?: number | Expression<number> | ResetValue;
4847
maxRetrySeconds?: number | Expression<number> | ResetValue;
@@ -64,7 +63,6 @@ export function getOpts(args: string | ScheduleOptions): SeparatedOpts {
6463
return {
6564
schedule: args.schedule,
6665
timeZone: args.timeZone,
67-
attemptDeadlineSeconds: args.attemptDeadlineSeconds,
6866
retryConfig: {
6967
retryCount: args.retryCount,
7068
maxRetrySeconds: args.maxRetrySeconds,
@@ -113,12 +111,6 @@ export interface ScheduleOptions extends options.GlobalOptions {
113111
/** The timezone that the schedule executes in. */
114112
timeZone?: timezone | Expression<string> | ResetValue;
115113

116-
/**
117-
* The deadline for job attempts in seconds. If the request handler does not respond by this deadline,
118-
* the request is cancelled and the attempt is marked as a `DEADLINE_EXCEEDED` failure.
119-
* The value must be between 15 and 1800. Defaults to 180.
120-
*/
121-
attemptDeadlineSeconds?: number | Expression<number> | ResetValue;
122114

123115
/** The number of retry attempts for a failed run. */
124116
retryCount?: number | Expression<number> | ResetValue;
@@ -205,7 +197,10 @@ export function onSchedule(
205197
scheduleTrigger: initV2ScheduleTrigger(separatedOpts.schedule, globalOpts, separatedOpts.opts),
206198
};
207199

208-
copyIfPresent(ep.scheduleTrigger, separatedOpts, "timeZone", "attemptDeadlineSeconds");
200+
copyIfPresent(ep.scheduleTrigger, separatedOpts, "timeZone");
201+
if (ep.timeoutSeconds) {
202+
ep.scheduleTrigger.attemptDeadlineSeconds = ep.timeoutSeconds;
203+
}
209204
copyIfPresent(
210205
ep.scheduleTrigger.retryConfig,
211206
separatedOpts.retryConfig,

0 commit comments

Comments
 (0)