Skip to content

Commit 84ce265

Browse files
committed
Wrap cloud function v1 operations with429Backoff
1 parent 017e7f5 commit 84ce265

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/gcp/cloudfunctions.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CODEBASE_LABEL,
1919
HASH_LABEL,
2020
} from "../functions/constants";
21+
import { with429Backoff } from "./retry429";
2122

2223
export const API_VERSION = "v1";
2324
const client = new Client({ urlPrefix: functionsOrigin(), apiVersion: API_VERSION });
@@ -209,10 +210,8 @@ export async function generateUploadUrl(projectId: string, location: string): Pr
209210
const endpoint = `/${parent}/functions:generateUploadUrl`;
210211

211212
try {
212-
const res = await client.post<unknown, { uploadUrl: string }>(
213-
endpoint,
214-
{},
215-
{ retryCodes: [503] },
213+
const res = await with429Backoff("generateUploadUrl", location, () =>
214+
client.post<unknown, { uploadUrl: string }>(endpoint, {}, { retryCodes: [503] }),
216215
);
217216
return res.body.uploadUrl;
218217
} catch (err: any) {
@@ -241,9 +240,8 @@ export async function createFunction(
241240
};
242241

243242
try {
244-
const res = await client.post<Omit<CloudFunction, OutputOnlyFields>, CloudFunction>(
245-
endpoint,
246-
cloudFunction,
243+
const res = await with429Backoff("create", cloudFunction.name, () =>
244+
client.post<Omit<CloudFunction, OutputOnlyFields>, CloudFunction>(endpoint, cloudFunction),
247245
);
248246
return {
249247
name: res.body.name,
@@ -405,14 +403,12 @@ export async function updateFunction(
405403
// Failure policy is always an explicit policy and is only signified by the presence or absence of
406404
// a protobuf.Empty value, so we have to manually add it in the missing case.
407405
try {
408-
const res = await client.patch<Omit<CloudFunction, OutputOnlyFields>, CloudFunction>(
409-
endpoint,
410-
cloudFunction,
411-
{
406+
const res = await with429Backoff("update", cloudFunction.name, () =>
407+
client.patch<Omit<CloudFunction, OutputOnlyFields>, CloudFunction>(endpoint, cloudFunction, {
412408
queryParams: {
413409
updateMask: fieldMasks.join(","),
414410
},
415-
},
411+
}),
416412
);
417413
return {
418414
done: false,
@@ -431,7 +427,7 @@ export async function updateFunction(
431427
export async function deleteFunction(name: string): Promise<Operation> {
432428
const endpoint = `/${name}`;
433429
try {
434-
const res = await client.delete<Operation>(endpoint);
430+
const res = await with429Backoff("delete", name, () => client.delete<Operation>(endpoint));
435431
return {
436432
done: false,
437433
name: res.body.name,

0 commit comments

Comments
 (0)