Skip to content

Commit d1cf3ab

Browse files
committed
Wrap cloud function v2 operations with429Backoff
1 parent 84ce265 commit d1cf3ab

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/gcp/cloudfunctionsv2.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { RequireKeys } from "../metaprogramming";
2020
import { captureRuntimeValidationError } from "./cloudfunctions";
2121
import { mebibytes } from "./k8s";
22+
import { with429Backoff } from "./retry429";
2223

2324
export const API_VERSION = "v2";
2425

@@ -273,8 +274,10 @@ export async function generateUploadUrl(
273274
location: string,
274275
): Promise<GenerateUploadUrlResponse> {
275276
try {
276-
const res = await client.post<never, GenerateUploadUrlResponse>(
277-
`projects/${projectId}/locations/${location}/functions:generateUploadUrl`,
277+
const res = await with429Backoff("generateUploadUrl", `${projectId}/${location}`, () =>
278+
client.post<never, GenerateUploadUrlResponse>(
279+
`projects/${projectId}/locations/${location}/functions:generateUploadUrl`,
280+
),
278281
);
279282
return res.body;
280283
} catch (err: any) {
@@ -308,10 +311,10 @@ export async function createFunction(cloudFunction: InputCloudFunction): Promise
308311
};
309312

310313
try {
311-
const res = await client.post<typeof cloudFunction, Operation>(
312-
components.join("/"),
313-
cloudFunction,
314-
{ queryParams: { functionId } },
314+
const res = await with429Backoff("create", cloudFunction.name, () =>
315+
client.post<typeof cloudFunction, Operation>(components.join("/"), cloudFunction, {
316+
queryParams: { functionId },
317+
}),
315318
);
316319
return res.body;
317320
} catch (err: any) {
@@ -399,13 +402,11 @@ export async function updateFunction(cloudFunction: InputCloudFunction): Promise
399402
);
400403

401404
try {
402-
const queryParams = {
403-
updateMask: fieldMasks.join(","),
404-
};
405-
const res = await client.patch<typeof cloudFunction, Operation>(
406-
cloudFunction.name,
407-
cloudFunction,
408-
{ queryParams },
405+
const queryParams = { updateMask: fieldMasks.join(",") };
406+
const res = await with429Backoff("update", cloudFunction.name, () =>
407+
client.patch<typeof cloudFunction, Operation>(cloudFunction.name, cloudFunction, {
408+
queryParams,
409+
}),
409410
);
410411
return res.body;
411412
} catch (err: any) {
@@ -419,7 +420,9 @@ export async function updateFunction(cloudFunction: InputCloudFunction): Promise
419420
*/
420421
export async function deleteFunction(cloudFunction: string): Promise<Operation> {
421422
try {
422-
const res = await client.delete<Operation>(cloudFunction);
423+
const res = await with429Backoff("delete", cloudFunction, () =>
424+
client.delete<Operation>(cloudFunction),
425+
);
423426
return res.body;
424427
} catch (err: any) {
425428
throw functionsOpLogReject({ name: cloudFunction } as InputCloudFunction, "update", err);

0 commit comments

Comments
 (0)