@@ -19,6 +19,7 @@ import {
19
19
import { RequireKeys } from "../metaprogramming" ;
20
20
import { captureRuntimeValidationError } from "./cloudfunctions" ;
21
21
import { mebibytes } from "./k8s" ;
22
+ import { with429Backoff } from "./retry429" ;
22
23
23
24
export const API_VERSION = "v2" ;
24
25
@@ -273,8 +274,10 @@ export async function generateUploadUrl(
273
274
location : string ,
274
275
) : Promise < GenerateUploadUrlResponse > {
275
276
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
+ ) ,
278
281
) ;
279
282
return res . body ;
280
283
} catch ( err : any ) {
@@ -308,10 +311,10 @@ export async function createFunction(cloudFunction: InputCloudFunction): Promise
308
311
} ;
309
312
310
313
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
+ } ) ,
315
318
) ;
316
319
return res . body ;
317
320
} catch ( err : any ) {
@@ -399,13 +402,11 @@ export async function updateFunction(cloudFunction: InputCloudFunction): Promise
399
402
) ;
400
403
401
404
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
+ } ) ,
409
410
) ;
410
411
return res . body ;
411
412
} catch ( err : any ) {
@@ -419,7 +420,9 @@ export async function updateFunction(cloudFunction: InputCloudFunction): Promise
419
420
*/
420
421
export async function deleteFunction ( cloudFunction : string ) : Promise < Operation > {
421
422
try {
422
- const res = await client . delete < Operation > ( cloudFunction ) ;
423
+ const res = await with429Backoff ( "delete" , cloudFunction , ( ) =>
424
+ client . delete < Operation > ( cloudFunction ) ,
425
+ ) ;
423
426
return res . body ;
424
427
} catch ( err : any ) {
425
428
throw functionsOpLogReject ( { name : cloudFunction } as InputCloudFunction , "update" , err ) ;
0 commit comments