@@ -18,6 +18,7 @@ import {
18
18
CODEBASE_LABEL ,
19
19
HASH_LABEL ,
20
20
} from "../functions/constants" ;
21
+ import { with429Backoff } from "./retry429" ;
21
22
22
23
export const API_VERSION = "v1" ;
23
24
const client = new Client ( { urlPrefix : functionsOrigin ( ) , apiVersion : API_VERSION } ) ;
@@ -209,10 +210,8 @@ export async function generateUploadUrl(projectId: string, location: string): Pr
209
210
const endpoint = `/${ parent } /functions:generateUploadUrl` ;
210
211
211
212
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 ] } ) ,
216
215
) ;
217
216
return res . body . uploadUrl ;
218
217
} catch ( err : any ) {
@@ -241,9 +240,8 @@ export async function createFunction(
241
240
} ;
242
241
243
242
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 ) ,
247
245
) ;
248
246
return {
249
247
name : res . body . name ,
@@ -405,14 +403,12 @@ export async function updateFunction(
405
403
// Failure policy is always an explicit policy and is only signified by the presence or absence of
406
404
// a protobuf.Empty value, so we have to manually add it in the missing case.
407
405
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 , {
412
408
queryParams : {
413
409
updateMask : fieldMasks . join ( "," ) ,
414
410
} ,
415
- } ,
411
+ } ) ,
416
412
) ;
417
413
return {
418
414
done : false ,
@@ -431,7 +427,7 @@ export async function updateFunction(
431
427
export async function deleteFunction ( name : string ) : Promise < Operation > {
432
428
const endpoint = `/${ name } ` ;
433
429
try {
434
- const res = await client . delete < Operation > ( endpoint ) ;
430
+ const res = await with429Backoff ( "delete" , name , ( ) => client . delete < Operation > ( endpoint ) ) ;
435
431
return {
436
432
done : false ,
437
433
name : res . body . name ,
0 commit comments