Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/deploy/functions/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
schedule?: string;
timeZone?: string | null;
retryConfig?: ScheduleRetryConfig | null;
attemptDeadlineSeconds?: number | null;
}

/** Something that has a ScheduleTrigger */
Expand Down Expand Up @@ -551,8 +552,8 @@
existingBackend.endpoints[endpoint.region][endpoint.id] = endpoint;
}
unreachableRegions.gcfV2 = gcfV2Results.unreachable;
} catch (err: any) {

Check warning on line 555 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err.status === 404 && err.message?.toLowerCase().includes("method not found")) {

Check warning on line 556 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 556 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value

Check warning on line 556 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 556 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .includes on an `any` value

Check warning on line 556 in src/deploy/functions/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
// customer has preview enabled without allowlist set
} else {
throw err;
Expand Down
6 changes: 6 additions & 0 deletions src/deploy/functions/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
schedule: string | Expression<string>;
timeZone?: Field<string>;
retryConfig?: ScheduleRetryConfig | null;
attemptDeadlineSeconds?: Field<number>;
}

export type HttpsTriggered = { httpsTrigger: HttpsTrigger };
Expand Down Expand Up @@ -456,7 +457,7 @@
// List param, we try resolving a String param instead.
try {
regions = params.resolveList(bdEndpoint.region, paramValues);
} catch (err: any) {

Check warning on line 460 in src/deploy/functions/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err instanceof ExprParseError) {
regions = [params.resolveString(bdEndpoint.region, paramValues)];
} else {
Expand Down Expand Up @@ -603,6 +604,11 @@
} else if (endpoint.scheduleTrigger.retryConfig === null) {
bkSchedule.retryConfig = null;
}
if (typeof endpoint.scheduleTrigger.attemptDeadlineSeconds !== "undefined") {
bkSchedule.attemptDeadlineSeconds = r.resolveInt(
endpoint.scheduleTrigger.attemptDeadlineSeconds,
);
}
return { scheduleTrigger: bkSchedule };
} else if ("taskQueueTrigger" in endpoint) {
const taskQueueTrigger: backend.TaskQueueTrigger = {};
Expand Down
2 changes: 2 additions & 0 deletions src/deploy/functions/runtimes/discovery/v1alpha1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ describe("buildFromV1Alpha", () => {
maxRetrySeconds: 120,
maxDoublings: 10,
},
attemptDeadlineSeconds: 300,
};

const yaml: v1alpha1.WireManifest = {
Expand Down Expand Up @@ -744,6 +745,7 @@ describe("buildFromV1Alpha", () => {
maxRetrySeconds: "{{ params.RETRY_DURATION }}",
maxDoublings: "{{ params.DOUBLINGS }}",
},
attemptDeadlineSeconds: "{{ params.ATTEMPT_DEADLINE }}",
};

const yaml: v1alpha1.WireManifest = {
Expand Down
2 changes: 2 additions & 0 deletions src/deploy/functions/runtimes/discovery/v1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
schedule: "Field<string>",
timeZone: "Field<string>?",
retryConfig: "object?",
attemptDeadlineSeconds: "Field<number>?",
});
if (ep.scheduleTrigger.retryConfig) {
assertKeyTypes(prefix + ".scheduleTrigger.retryConfig", ep.scheduleTrigger.retryConfig, {
Expand Down Expand Up @@ -287,8 +288,8 @@
retry: ep.eventTrigger.retry,
};
// Allow serviceAccountEmail but prefer serviceAccount
if ("serviceAccountEmail" in (ep.eventTrigger as any)) {

Check warning on line 291 in src/deploy/functions/runtimes/discovery/v1alpha1.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
eventTrigger.serviceAccount = (ep.eventTrigger as any).serviceAccountEmail;

Check warning on line 292 in src/deploy/functions/runtimes/discovery/v1alpha1.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .serviceAccountEmail on an `any` value

Check warning on line 292 in src/deploy/functions/runtimes/discovery/v1alpha1.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
}
copyIfPresent(
eventTrigger,
Expand Down Expand Up @@ -377,6 +378,7 @@
} else if (ep.scheduleTrigger.retryConfig === null) {
st.retryConfig = null;
}
copyIfPresent(st, ep.scheduleTrigger, "attemptDeadlineSeconds");
triggered = { scheduleTrigger: st };
} else if (build.isTaskQueueTriggered(ep)) {
const tq: build.TaskQueueTrigger = {};
Expand Down
27 changes: 27 additions & 0 deletions src/gcp/cloudscheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,32 @@ describe("cloudscheduler", () => {
},
});
});

it("should copy attemptDeadlineSeconds for v1 endpoints", async () => {
expect(
await cloudscheduler.jobFromEndpoint(
{
...V1_ENDPOINT,
scheduleTrigger: {
schedule: "every 1 minutes",
attemptDeadlineSeconds: 300,
},
},
"appEngineLocation",
"1234567",
),
).to.deep.equal({
name: "projects/project/locations/appEngineLocation/jobs/firebase-schedule-id-region",
schedule: "every 1 minutes",
timeZone: "America/Los_Angeles",
attemptDeadline: "300s",
pubsubTarget: {
topicName: "projects/project/topics/firebase-schedule-id-region",
attributes: {
scheduled: "true",
},
},
});
});
});
});
11 changes: 11 additions & 0 deletions src/gcp/cloudscheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface Job {
schedule: string;
description?: string;
timeZone?: string | null;
attemptDeadline?: string | null;

// oneof target
httpTarget?: HttpTarget;
Expand Down Expand Up @@ -195,6 +196,9 @@ function needUpdate(existingJob: Job, newJob: Job): boolean {
if (existingJob.timeZone !== newJob.timeZone) {
return true;
}
if (existingJob.attemptDeadline !== newJob.attemptDeadline) {
return true;
}
if (newJob.retryConfig) {
if (!existingJob.retryConfig) {
return true;
Expand Down Expand Up @@ -258,6 +262,13 @@ export async function jobFromEndpoint(
);
}
job.schedule = endpoint.scheduleTrigger.schedule;
proto.convertIfPresent(
job,
endpoint.scheduleTrigger,
"attemptDeadline",
"attemptDeadlineSeconds",
nullsafeVisitor(proto.durationFromSeconds),
);
if (endpoint.scheduleTrigger.retryConfig) {
job.retryConfig = {};
proto.copyIfPresent(
Expand Down
Loading